【CSP-S 2020】补题记录
T1 [CSP-S 2020]儒略日
模拟,可以找找周期规律,然后模拟,这样可能会大大减小代码量
点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int year_400=146097;
inline int read()
{
int w=0,f=1;
char ch=getchar();
while(ch<'0' || ch>'9')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
{
w=(w<<3)+(w<<1)+(ch^48);
ch=getchar();
}
return w*f;
}
int q,r,t;
int y[year_400];
int d[year_400];
int m[year_400];
int month_day(int year,int month)
{
if(month==2)
{
if(year%4) return 28;
else if(year%100) return 29;
else if(year%400) return 28;
else return 29;
}
if(month==4 || month==6 || month==9 || month==11)
{
return 30;
}
return 31;
}
signed main()
{
q=read();
m[0]=d[0]=1;
for(int i=1;i<year_400;i++)
{
d[i]=d[i-1]+1;
m[i]=m[i-1];
y[i]=y[i-1];
if(d[i]>month_day(y[i],m[i])) m[i]++,d[i]=1;
if(m[i]>12) y[i]++,m[i]=1;
}
while(q--)
{
r=read();
if(r>2299160)
{
r-=2159351;
t=r/year_400*400+1200;
r%=year_400;
}
else
{
t=r/1461*4-4712;
r%=1461;
}
if(t+y[r]>0) cout<<d[r]<<" "<<m[r]<<" "<<y[r]+t<<endl;
else cout<<d[r]<<" "<<m[r]<<" "<<1-t-y[r]<<" "<<"BC"<<endl;
}
return 0;
}