zoj 3403 Strange Calendar III

来源:互联网 发布:centos设置中文输入法 编辑:程序博客网 时间:2024/05/16 09:57

点击打开题目链接

Strange Calendar III

Time Limit: 2 Seconds      Memory Limit: 65536 KB

As we know, in the Bzu planet and in the cc98 planet, people use special calendar which is similar to that used in the earth. In fact, in the BoMb planet, people use a similar calendar as well!

As a matter of fact, people who live in the BoMb planet are all from the earth after a big bomb blew up on the earth. Because of being used to the calendar in the earth, they use Day,Month and Year in the calendar in the BoMb too. But the operational cycle of the BoMb planet is so ridiculous that people have to make strange rules for their new calendar.

The rules are listed below:

  1. For Year X, there are f(X) months in total, where f(X) = (X mod 12) + 1.
  2. For each year, there are i3 day(s) in the ith month.
  3. There are also leap years in the BoMb planet. For Year X, if X mod 11 = 0, it is considered as a leap year and there are 1 day more in the first month of the year.

Now given two dates in the format of BoMb calendar, you are to calculate how many days there are in total between the two days(include the two days).

Input

The input contains multiple test cases. There are only two lines in each test case. The first line is a string "m1-d1-y1", indicating the d1th day in the m1th month of Year y1. The second line is a string "m2-d2-y2" indicating the date of the other day. You can assume the two dates are legal in BoMb calendar and are diffrent, and y1 and y2 are in the range of [0, 109].

Output

For each test case, output a single line the number of days between the two days (include the two days) given in the input.

Sample Input

2-2-142-3-15

Sample Output

38
题意:第x年有(x mod 12)+1个月,第i个月有i*i*i天,如果x mod 11==0那么这一年的第一个月比平时多一天,有两天,给你两个时间,求他们之间间隔多长时间。

不能直接求,如果直接求得话容易乱了套,越做越乱,我的方法是求出每个时间到0-0-0的时间,在相减。中间还有好几处陷阱,wa了好几次。。。总算过了~

代码:

#include<iostream>#include<algorithm>#include<cmath>#include<cstring>#include<cstdio>using namespace std;typedef long long ll;ll month[13],year[13];ll ans;void init()//12年一个循环,求出12年一共有多少天{    year[0]=0;    month[0]=0;    for(int i=1;i<13;i++)    {        month[i]=i*i*i;        year[i]=month[i]+year[i-1];        //cout<<i<<"&&"<<month[i]<<"**"<<year[i]<<endl;        ans+=year[i];    }}ll data(ll m,ll d,ll y)//求出y年m月d天道0年0月0天一共有多少天{    ll ansd=0;    int yy=y%12+1;    ansd+=(y/12)*ans;    for(int i=1;i<yy;i++)        ansd+=year[i];    for(int i=1;i<m;i++)        ansd+=month[i];        ansd+=d;    if(y>10)        ansd+=(y-1)/11;//当y%11==0时多出来的那一天。    if(y%11==0&&m>1)//当年是否也多一天        ansd++;    return ansd;}int main(){    ll d1,m1,y1,d2,m2,y2;    init();    while(~scanf("%lld-%lld-%lld",&m1,&d1,&y1))    {        scanf("%lld-%lld-%lld",&m2,&d2,&y2);        //cout<<data(m1,d1,y1)<<"&&"<<data(m2,d2,y2)<<endl;        ll sum=fabs(data(m1,d1,y1)-data(m2,d2,y2))+1;       if(y1==0&&y2!=0||y1!=0&&y2==0)//当有一个是从0年开始的话,特殊处理             sum++;       printf("%lld\n",sum);    }    return 0;}

 



0 0
原创粉丝点击