「CSP-S 2020」儒略日
description
solution
这道题作为T1,对选手们仔细看清题目的好习惯,以及不为2h调试、5k代码而心态爆炸的重要能力进行了较好的锻炼,
特别准备的只有答案满足\(\le 10^9\)更是让每个同学从此对考场时要仔细看数据范围印象深刻。
实在是出题人良心的馈赠,将为每位选手的oi之路上平添一份助力。
没什么可说的,大力分类讨论+模拟
貌似二分写法会简单很多,不过5k代码丝毫不虚
在此,向该题的出题人表示最诚挚的问候和衷心的祝愿。
code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*f;
}
ll q,r;
int mo_ping[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int mo_run[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int sum_ping[13],sum_run[13];
inline void calcBC(ll r){
ll zq=366+365+365+365;
ll t=r/zq,p=r%zq;
ll y,m,d;
y=4713-t*4;
if(p>=366+365+365) p-=366+365+365,y-=3;
else if(p>=366+365) p-=366+365,y-=2;
else if(p>=366) p-=366,y-=1;
if(y%4==1){
for(int i=1;i<=12;++i)
if(sum_run[i]>p){m=i;p-=sum_run[i-1];break;}
d=p+1;
}
else{
for(int i=1;i<=12;++i)
if(sum_ping[i]>p){m=i;p-=sum_ping[i-1];break;}
d=p+1;
}
printf("%lld %lld %lld BC\n",d,m,y);
return ;
}
inline void calcjulian(ll r){
ll zq=366+365+365+365;
ll t=r/zq,p=r%zq;
ll y,m,d;
y=4*t+1;
if(p>=365+365+365) p-=365+365+365,y+=3;
else if(p>=365+365) p-=365+365,y+=2;
else if(p>=365) p-=365,y+=1;
if(y%4==0){
for(int i=1;i<=12;++i)
if(sum_run[i]>p){m=i;p-=sum_run[i-1];break;}
d=p+1;
}
else{
for(int i=1;i<=12;++i)
if(sum_ping[i]>p){m=i;p-=sum_ping[i-1];break;}
d=p+1;
}
printf("%lld %lld %lld\n",d,m,y);
return ;
}
inline void calc1582(ll r){
ll y,m,d;
y=1582;
if(r<17) m=10,d=r+15;
else if(r<47) m=11,d=r-16;
else m=12,d=r-46;
printf("%lld %lld %lld\n",d,m,y);
return ;
}
inline void calcbef1600(ll r){
ll y,m,d;
for(int i=1583;i<=1599;++i){
ll ty=i%4?365:366;
if(r<ty){
y=i;
if(y%4==0){
for(int i=1;i<=12;++i)
if(sum_run[i]>r){m=i;r-=sum_run[i-1];break;}
d=r+1;
}
else{
for(int i=1;i<=12;++i)
if(sum_ping[i]>r){m=i;r-=sum_ping[i-1];break;}
d=r+1;
}
break;
}
r-=ty;
}
printf("%lld %lld %lld\n",d,m,y);
return ;
}
int main(){
freopen("julian.in","r",stdin);
freopen("julian.out","w",stdout);
q=read();
for(int i=1;i<=12;++i) sum_ping[i]=sum_ping[i-1]+mo_ping[i],sum_run[i]=sum_run[i-1]+mo_run[i];
ll zq=366+365+365+365;
ll r1=zq*1178; //\xb9\xabԪǰ1\xc4\xea1\xd4\xc21\xc8\xd5
ll r2=r1+366; //\xb9\xabԪ1\xc4\xea1\xd4\xc21\xc8\xd5
ll r3=r2+zq*395+365+sum_ping[9]+3;//\xb9\xabԪ1582\xc4\xea10\xd4\xc24\xc8\xd5
ll r4=r3+1; //\xb9\xabԪ1582\xc4\xea10\xd4\xc215\xc8\xd5
while(q--){
r=read();
if(r<r2) calcBC(r);
else if(r<=r3) calcjulian(r-r2);
else{
r-=r4;
if(r<78) calc1582(r);
else{
ll y,m,d;
r-=78;
ll r5=4*366+13*365;
if(r<r5) calcbef1600(r);
else{
r-=r5;
ll bigzq=97*366+303*365,r6=25*366+75*365,r7=r6*2-1,r8=r6*3-2;
ll t=r/bigzq,p=r%bigzq,zq=366+365*3;
y=1600+t*400;
if(p<r6){
y+=(p/zq)*4;p%=zq;
if(p>=366+365+365) p-=366+365+365,y+=3;
else if(p>=366+365) p-=366+365,y+=2;
else if(p>=366) p-=366,y+=1;
if(y%4==0){
for(int i=1;i<=12;++i)
if(sum_run[i]>p){m=i;p-=sum_run[i-1];break;}
d=p+1;
}
else{
for(int i=1;i<=12;++i)
if(sum_ping[i]>p){m=i;p-=sum_ping[i-1];break;}
d=p+1;
}
printf("%lld %lld %lld\n",d,m,y);
continue;
}
else if(p<r7){
p-=r6;y+=100;
if(p>=365&&p<365+365) p-=365,y++;
else if(p>=365+365&&p<365*3) p-=365*2,y+=2;
else if(p>=365*3&&p<365*4) p-=365*3,y+=3;
else if(p>=365*4){
y+=4;
p-=365*4;
y+=(p/zq)*4;p%=zq;
if(p>=366+365+365) p-=366+365+365,y+=3;
else if(p>=366+365) p-=366+365,y+=2;
else if(p>=366) p-=366,y+=1;
}
if(y%4==0&&y%100!=0){
for(int i=1;i<=12;++i)
if(sum_run[i]>p){m=i;p-=sum_run[i-1];break;}
d=p+1;
}
else{
for(int i=1;i<=12;++i)
if(sum_ping[i]>p){m=i;p-=sum_ping[i-1];break;}
d=p+1;
}
printf("%lld %lld %lld\n",d,m,y);
continue;
}
else if(p<r8){
p-=r7;y+=200;
if(p>=365&&p<365+365) p-=365,y++;
else if(p>=365+365&&p<365*3) p-=365*2,y+=2;
else if(p>=365*3&&p<365*4) p-=365*3,y+=3;
else if(p>=365*4){
y+=4;
p-=365*4;
y+=(p/zq)*4;p%=zq;
if(p>=366+365+365) p-=366+365+365,y+=3;
else if(p>=366+365) p-=366+365,y+=2;
else if(p>=366) p-=366,y+=1;
}
if(y%4==0&&y%100!=0){
for(int i=1;i<=12;++i)
if(sum_run[i]>p){m=i;p-=sum_run[i-1];break;}
d=p+1;
}
else{
for(int i=1;i<=12;++i)
if(sum_ping[i]>p){m=i;p-=sum_ping[i-1];break;}
d=p+1;
}
printf("%lld %lld %lld\n",d,m,y);
continue;
}
else{
p-=r8;y+=300;
if(p>=365&&p<365+365) p-=365,y++;
else if(p>=365+365&&p<365*3) p-=365*2,y+=2;
else if(p>=365*3&&p<365*4) p-=365*3,y+=3;
else if(p>=365*4){
y+=4;
p-=365*4;
y+=(p/zq)*4;p%=zq;
if(p>=366+365+365) p-=366+365+365,y+=3;
else if(p>=366+365) p-=366+365,y+=2;
else if(p>=366) p-=366,y+=1;
}
if(y%4==0&&y%100!=0){
for(int i=1;i<=12;++i)
if(sum_run[i]>p){m=i;p-=sum_run[i-1];break;}
d=p+1;
}
else{
for(int i=1;i<=12;++i)
if(sum_ping[i]>p){m=i;p-=sum_ping[i-1];break;}
d=p+1;
}
printf("%lld %lld %lld\n",d,m,y);
continue;
}
}
}
}
}
return 0;
}