ZOJ 3403 Strange Calendar III


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-14
2-3-15
Sample Output
38
 
题目:给定一个特殊的年月日的定义:第n年有(n%12)+1个月,第i个月有i*i*i天,if(n%11)==0,那么这年为闰年,改年的第一个月多一天。求给定的两个日期之间一共有多少天。
思路:整体就是模拟就行,先打表把前12年的每月的天数求出来,同时把12年的总天数求出来。那么计算时只需要计算n/12是多少,还有n%12年的天数单独处理就行了。
代码:
#include <iostream>
#include <cstdio>
using namespace std;
int a[14][14];
long long sum=0;
void init()
{
    for(int i=1;i<=12;i++)
    {
        a[i][0]=0;
        for(int j=1;j<=i;j++)
        {
            a[i][j]=j*j*j;
            a[i][0]+=a[i][j];
        }
        sum+=a[i][0];
    }
}
struct node
{
    int m,d,y;
}l,r;
long long solve(node t)
{
    long long ans=0;
    int d=t.y/12,r=t.y%12;
    ans+=sum*d;                   //计算n里面有多少个12年
    int i,j;
    for(i=1;i<=r;i++)             //单独处理剩下的年份
    {
        ans+=a[i][0];
    }
    for(j=1;j<t.m;j++)            //第n年的每个月单独处理
    {
        if(j==1&&t.y%11==0) ans++;
        ans+=a[i][j];
    }
    if(t.y==0) d=0;               //计算(n-1)年里面有多少个闰月,第n年已经在上面单独处理了
    else d=(t.y-1)/11+1;
    ans=ans+d+t.d;               //第n年的第m月单独处理
    return ans;
}
int main()
{
    init();
    /*while(scanf("%d-%d-%d",&l.m,&l.d,&l.y)!=EOF)
    {
        cout<<solve(l)<<endl;
    }*/
    while(scanf("%d-%d-%d",&l.m,&l.d,&l.y)!=EOF)
    {
        scanf("%d-%d-%d",&r.m,&r.d,&r.y);
        if(l.y>r.y||l.y==r.y&&l.m>r.m||l.y==r.y&&l.m==r.m&&l.d>r.d)  //处理第一个日期在第二个日期后面的情况
        {
            swap(l.y,r.y);
            swap(l.m,r.m);
            swap(l.d,r.d);
        }
        l.d--;
        long long ans=solve(r)-solve(l);
        printf("%lld\n",ans);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值