zoj 3403 Strange Calendar III
来源:互联网 发布:centos设置中文输入法 编辑:程序博客网 时间:2024/05/16 09:57
点击打开题目链接
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:
- For Year X, there are f(X) months in total, where f(X) = (X mod 12) + 1.
- For each year, there are i3 day(s) in the ith month.
- 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;}
- ZOJ 3403 Strange Calendar III
- zoj 3403 Strange Calendar III
- zoj(Strange Calendar III)
- Strange Calendar III zoj 4011
- (zju 3403)Strange Calendar III
- zju 3403 Strange Calendar III
- zoj 3191 Strange Clock
- ZOJ 3191 Strange Clock
- ZOJ 2674 Strange Limit
- ZOJ 2674 Strange Limit
- ZOJ 2674 Strange Limit
- 732. My Calendar III
- 732. My Calendar III
- ZOJ 3332 Strange Country II
- zoj Strange Country II 3332
- [ZOJ 3318] Strange Country [搜索]
- ZOJ 3332 Strange Country II
- ZOJ 3332 Strange Country II
- 郑州治理露天烧烤 面临“烤”验 取证难 回潮易
- Linux服务器开发初步
- Nio学习3——基础模型:多路复用模型
- Eclipse中出现Setting build path has encountered a problem的解决方法
- nyoj 37 回文字符串题解
- zoj 3403 Strange Calendar III
- Android: 创建一个AlertDialog对话框,必须按确定或取消按钮才能关闭对话框,禁止按[返回键]或[搜索键]关闭
- 动态加载这一点,可以从Apache处理。htaccess文件看出来。你修改了。htaccess后,就
- Mysql索引优化浅谈
- UI标签库专题一:JEECG智能开发平台 BaseTag(样式表和JS引入标签)
- android驱动学习---led实验
- JAVA 线程000
- 【Python】上下文管理 with...as...
- android 4.0 签名并混淆