ZOJ 3326 An Awful Problem 神坑模拟

来源:互联网 发布:flyme升级清除数据吗 编辑:程序博客网 时间:2024/05/16 14:42
点击打开链接

An Awful Problem

Time Limit: 1 Second      Memory Limit: 32768 KB

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. ThenT test cases follow. Thei-th line of the nextT 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

Author: GUAN, Yao
Source: The 7th Zhejiang Provincial Collegiate Programming Contest

交了11次,WA了11次,各种测试数据各种过,检查了一遍又一遍,代码都很完美,有史以来,最坑爹的模拟找我碰上了,附上zeh挫折码,谁能帮我AC了,以身相娶也不难。

#include<stdio.h>int main(){    int tt;    //freopen("in.txt","r",stdin);    scanf("%d",&tt);    while(tt--)    {        int y1,m1,d1,y2,m2,d2,ans=0;        scanf("%d%d%d%d%d%d",&y1,&m1,&d1,&y2,&m2,&d2);        if(y2-y1>=2)//求年的天数        {            for(int i=y1+1; i<=y2-1; i++)                if((i%4==0&&i%100!=0)||i%400==0)                    ans+=53;                else ans+=52;        }        //printf("年==%d\n",ans);        if(y1<y2)//如果不再同一年        {            for(int i=m1+1; i<=11; i++)//开始日期的月数            {                if(i==2)                {                    if((y1%4==0&&y1%100!=0)||y1%400==0)                        ans+=10;                    else ans+=9;                }                else if(i==3||i==5||i==7)                    ans+=11;                else if(i==11)                    ans+=10;            }            for(int i=2;i<=m2-1;i++)//结束日期的月数            {                if(i==2)                {                    if((y2%4==0&&y2%100!=0)||y2%400==0)                        ans+=10;                    else ans+=9;                }                else if(i==3||i==5||i==7)                    ans+=11;                else if(i==11)                    ans+=10;            }        }        else if(y1==y2)//如果在同一年求月数        {            if((m2-m1)>=1)            {                for(int i=m1+1; i<=m2-1; i++)                {                    if(i==2)                    {                        if((y2%4==0&&y2%100!=0)||y2%400==0)                            ans+=10;                        else ans+=9;                    }                    else if(i==3||i==5||i==7)                        ans+=11;                    else if(i==11)                        ans+=10;                }            }            //printf("第二个书的月%d\n",ans);        }        int t;        if(m1==3||m1==5||m1==7)            t=31;        else if(m1==11)            t=30;        else if(m1==2)        {            if((y1%4==0&&y1%100!=0)||y1%400==0)                t=29;            else t=28;        }        else t=0;        if(m1==m2)        {            if(m1==2||m1==3||m1==5||m1==7||m1==11)            {                for(int i=d1; i<=d2; i++)                    if(i==2||i==3||i==5||i==7||i==11||i==13||i==17||i==19||i==23||i==29||i==31)                        ans++;            }            printf("%d\n",ans);        }        else        {            if(m1==2||m1==3||m1==5||m1==7||m1==11)            {                for(int i=d1; i<=t; i++)                    if(i==2||i==3||i==5||i==7||i==11||i==13||i==17||i==19||i==23||i==29||i==31)                        ans++;            }            //printf("第1次的天书%d\n",ans);            if(m2==2||m2==3||m2==5||m2==7||m2==11)            {                for(int i=2; i<=d2; i++)                    if(i==2||i==3||i==5||i==7||i==11||i==13||i==17||i==19||i==23||i==29||i==31)                        ans++;            }            //printf("第二次的天书%d\n",ans);            printf("%d\n",ans);        }        //printf("第一个数的月=%d\n",ans);    }    return 0;}


原创粉丝点击