zoj(Strange Calendar III)

日历结算只能找规律,不能模拟(超时)!!!

 

#include<stdio.h>
#include<math.h>
#include<string.h>
double firstday,firstmonth,firstyear;
double lastday,lastmonth,lastyear;
double sumdays;
double oneyear[15];

void init()
{
 sumdays=0;

    for(int i=1;i<=12;i++)
    {
        int t=0;
        for(int j=1;j<=i;j++)
        {
            t+=j*j*j;
        }
        oneyear[i]=t;
        sumdays+=t;
       // printf("%d:%d/n",i,total);
    }
}

double sumday(int year,int month,int day)
{
    double total=0.0;
    int cnt=(year)/12;
    total+=sumdays*cnt;
    int temp=(cnt*12)/11;
    total+=temp;
   for(int i=temp*11;i<(12*cnt);i++) if(i%11==0) total+=1;
    for(int i=12*cnt;i<year;i++)
    {
      if(i%11==0)
      total+=oneyear[i%12+1]+1;
      else
      total+=oneyear[i%12+1];
    }
    if(month==1)
    {
        return total+day;
    }
    else
    {
        if(year%11==0)
        total+=2;
        else
        total+=1;
        for(int i=2;i<month;i++)
        total+=i*i*i;
        return total+day;
    }
}

int main()
{
    init();
    char ch1,ch2;
    while(scanf("%lf%c%lf%c%lf",&firstmonth,&ch1,&firstday,&ch2,&firstyear)==5)
    {
        //getchar();
        scanf("%lf%c%lf%c%lf",&lastmonth,&ch1,&lastday,&ch2,&lastyear);
       // getchar();
        double tot1=sumday(firstyear,firstmonth,firstday);
        double tot2=sumday(lastyear,lastmonth,lastday);
        double tot=fabs(tot1-tot2);
        printf("%.0lf/n",tot+1.0);
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值