2014ACM集训13级PK赛2-An Awful Problem
来源:互联网 发布:知乎绑定邮箱 编辑:程序博客网 时间:2024/06/01 10:06
Description
In order to encourage Hiqivenfin to study math, his mother gave him a sweet candy when the day of the month was a prime number. Hiqivenfin was happy with that. But several days later, his mother modified the rule so that he could get a candy only when the day of the month was a prime number and the month was also a prime number. He felt a bit upset because he could get fewer candies. What's worse, his mother changed the rule again and he had to answer a question before he could get a candy in those days. The question was that how many candies he could get in the given time interval. Hiqivenfin wanted to cry and asked you for help. He promised to give you half of a candy if you could help him to solve this problem.
Input
There are multiple test cases. The first line of input is an integer T (0 < T <= 50), indicating the number of test cases. Then T test cases follow. The i-th line of the next T lines contains two dates, the day interval of the question. The format of the date is "yyyy mm dd". You can assume both dates are valid. Hiqivenfin was born at 1000-01-01 and would not die after 2999-12-31, so the queries are all in this interval.
Hiqivenfin didn't seem to be an earthman, but the calendar was the same as that we usually use. That is to say, you need to identify leap years, where February has 29 days. In the Gregorian calendar, leap years occur in years exactly divisible by four. So, 1993, 1994, and 1995 are not leap years, while 1992 and 1996 are leap years. Additionally, the years ending with 00 are leap years only if they are divisible by 400. So, 1700, 1800, 1900, 2100, and 2200 are not leap years, while 1600, 2000, and 2400 are leap years.
Output
Output the number of candies Hiqivenfin could get in the time interval. Both sides of the interval are inclusive.
Sample Input
21000 01 01 1000 01 312000 02 01 2000 03 01
Sample Output
010
#include <stdio.h>#include <math.h>#include <stdlib.h>bool num[40];int pingd[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};int rund[] = {0,31,29,31,30,31,30,31,31,30,31,30,31};int pingde[] = {0,0,9,11,0,11,0,11,0,0,0,10,0};int runde[] = {0,0,10,11,0,11,0,11,0,0,0,10,0};int pingdey = 9 + 11 + 11 + 11 + 10;int rundey = 10 + 11 + 11 + 11 + 10;int pd (int y){ if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) return 1; else return 0;}void jiuzheng(int *y1,int *m1,int *d1,int *y2,int *m2,int *d2){ int t; if (*y1 > *y2) { t = *y1; *y1 = *y2; *y2 = t; t = *m1; *m1 = *m2; *m2 = t; t = *d1; *d1 = *d2; *d2 = t; } else if (*y1 == *y2) { if (*m1 > *m2) { t = *y1; *y1 = *y2; *y2 = t; t = *m1; *m1 = *m2; *m2 = t; t = *d1; *d1 = *d2; *d2 = t; } else if (*m1 == *m2) { if (*d1 > *d2) { t = *y1; *y1 = *y2; *y2 = t; t = *m1; *m1 = *m2; *m2 = t; t = *d1; *d1 = *d2; *d2 = t; } } }}int main(){ int i,k,j; for (i = 2; i < 40; i++) num[i] = true; for (i = 2; i <= sqrt(40); i++) { if (num[i]) for(k = i + i; k < 40; k += i) num[k] = false; } int N; scanf ("%d",&N); while (N--) { int ans = 0; int y1,y2,m1,m2,d1,d2; scanf ("%d%d%d%d%d%d",&y1,&m1,&d1,&y2,&m2,&d2); jiuzheng (&y1,&m1,&d1,&y2,&m2,&d2); int tf; if (y1 == y2) { tf = pd(y1); if (m1 == m2) { if (num[m1]) for (i = d1; i <= d2; i++) if(num[i]) ans++; } else { if (tf) { if (num[m1]) for (i = d1; i <= rund[m1]; i++) if (num[i]) ans++; for (i = m1 + 1; i < m2; i++) if (num[i]) ans += runde[i]; if (num[m2]) for (i = 1; i <= d2; i++) if (num[i]) ans++; } else { if (num[m1]) for (i = d1; i <= pingd[m1]; i++) if (num[i]) ans++; for (i = m1 + 1; i < m2; i++) if (num[i]) ans += pingde[i]; if (num[m2]) for (i = 1; i <= d2; i++) if (num[i]) ans++; } } } else { int tf = pd(y1); if (tf) { if (num[m1]) for (i = d1; i <= rund[m1]; i++) if (num[i]) ans++; for (i = m1 + 1; i <= 12; i++) if (num[i]) ans += runde[i]; } else { if (num[m1]) for (i = d1; i <= pingd[m1]; i++) if (num[i]) ans++; for (i = m1 + 1; i <= 12; i++) if (num[i]) ans += pingde[i]; } for (i = y1 + 1; i < y2; i++) if (pd(i)) ans += rundey; else ans += pingdey; tf = pd(y2); if (tf) { for (i = 1;i < m2;i++) if (num[i]) ans += runde[i]; }else { for (i = 1;i < m2;i++) if (num[i]) ans += pingde[i]; } if (num[m2]) for (i = 1;i <= d2;i++) if (num[i]) ans++; } printf ("%d\n",ans); } return 0;}
麻烦的水题
- 2014ACM集训13级PK赛2-An Awful Problem
- 2014ACM集训13级PK赛2-Somali Pirates
- 2014ACM集训13级PK赛2-Wu Xing
- 2014ACM集训13级PK赛2-Ordinal Numbers
- 2014ACM集训13级PK赛2-Conic Section
- 2014ACM集训13级PK赛2-Kagome Kagome
- 2014ACM集训13级PK赛2-Javabeans
- 2014ACM集训13级PK赛2-Median
- 2014寒假ACM集训13级PK赛-翻转排序
- 2014寒假ACM集训13级PK赛-购买矿石
- 2014ACM集训13级PK赛3-Taxi Fare
- 2014ACM集训13级PK赛3-Modular Inverse
- 2014ACM集训13级PK赛3-Friends
- 2014ACM集训13级PK赛3-Java Beans
- 2014ACM集训13级PK赛4-K-Nice
- 2014ACM集训13级PK赛4-Light Bulb
- 2014ACM集训13级PK赛5-Easy Task
- 2014ACM集训13级PK赛2-Who is Older?
- 1047. Super Snooker
- LInux下安装配置Maven
- 暴力破解法求最大公约数+辗转相除法求最大公约数+暴力破解法求最下公倍数
- 我爱北京
- 图像增强——同态滤波
- 2014ACM集训13级PK赛2-An Awful Problem
- codec engine代码阅读四---CE_DIR/examples/ti/sdo/ce/examles/codecs/videnc_copy
- 2014.3.9记录
- WEB安全
- 显示通知栏
- 万年历
- codec engine代码阅读五---CE_DIR/examples/ti/sdo/ce/examles/servers/video_copy
- 用五种不同的方法遍历数组
- 黑马程序员日记一:基础重中之中—构造方法 成员方法 类 内部类