题意是2016.4.1过x天,其中抛去六日和四月一,是几号;
日期模拟题一个。。先不要脸的搞一个日期模板。。然后再利用400年一循环,打表二分一下子。。
基本没有写过日期的模拟题,总结起来下次看看能不能做出来吧。。。
弱鸡加油↖(^ω^)↗
#include <iostream>
using namespace std;
//日期函数
int all=184500;
int n,k;
int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
struct date{
int year,month,day;
};
//判闰年
inline int leap(int year){
return (year%4==0&&year%100!=0)||year%400==0;
}
//比较日期大小
inline int datecmp(date a,date b){
if (a.year!=b.year)
return a.year-b.year;
if (a.month!=b.month)
return a.month-b.month;
return a.day-b.day;
}
//返回指定日期是星期几
int weekday(date a){
int tm=a.month>=3?(a.month-2):(a.month+10);
int ty=a.month>=3?a.year:(a.year-1);
return (ty+ty/4-ty/100+ty/400+(int)(2.6*tm-0.2)+a.day)%7;
}
//日期转天数偏移
int date2int(date a){
int ret=a.year*365+(a.year-1)/4-(a.year-1)/100+(a.year-1)/400,i;
days[1]+=leap(a.year);
for (i=0;i<a.month-1;ret+=days[i++]);
days[1]=28;
return ret+a.day;
}
//天数偏移转日期
date int2date(int a){
date ret;
ret.year=a/146097*400;
for (a%=146097;a>=365+leap(ret.year);a-=365+leap(ret.year),ret.year++);
days[1]+=leap(ret.year);
for (ret.month=1;a>=days[ret.month-1];a-=days[ret.month-1],ret.month++);
days[1]=28;
ret.day=a+1;
return ret;
}
int biao[1000000];
int cnt=1;
void init(){
date A;
A.day=1;
A.month=4;
A.year=2016;
date B;
B.day=1;
B.month=4;
B.year=2416;
int l=date2int(A);
int r=date2int(B);
date C;
for(int i=l;i<r;i++){
C=int2date(i);
if(C.month==4&&C.day==1){
biao[cnt]=biao[cnt-1];
}
else if(weekday(C)==6||weekday(C)==0){
biao[cnt]=biao[cnt-1];
}
else{
biao[cnt]=biao[cnt-1]+1;
}
++cnt;
}
}
int main()
{
int t;
init();
cin>>t;
while(t--){
cin>>k>>n;
int ad=all*n;
if(ad%k!=0){
ad=ad/k+1;
}
else{
ad=ad/k;
}
int ans=0;
date A;
A.day=1;
A.month=4;
A.year=2016;
int a=date2int(A)-1;
while(ad>biao[cnt-1]){
ad-=biao[cnt-1];
ans+=cnt-1;
}
int x=(int)(lower_bound(biao+1,biao+cnt,ad)-biao);
a+=x;
/***
for(int i=1;i<cnt;i++){
if(biao[i]==ad){
a+=i;
break;
}
}
***/
A=int2date(ans+a);
cout<<A.year<<"/";
if(A.month<10)
cout<<"0";
cout<<A.month<<"/";
if(A.day<10)
cout<<"0";
cout<<A.day;
date B;
B.day=31;
B.month=12;
B.year=2060;
if(datecmp(A,B)>0){
cout<<", A sad story ==";
}
cout<<endl;
}
return 0;
}