又改了好久,大部分数据都可以过了
然而我在大样例中(julian3.in和julian3.out)发现这么了一组数据:
in:
1
572844041
题解代码输出:
11 8 1563681
我的代码输出:
12 8 1563681(比题解代码的输出多了一天)
然而我又调了很久很久也不知道错了哪里......求助高手!
我调了很久以后的代码如下:(朴素做法))
//P7075 [CSP-S2020] 儒略日
#include<bits/stdc++.h>
using namespace std;
const int N1=2299159;//-4713.1.1~1582.10.3总天数
const int N2=1461;//儒略历中每4年的天数
const int N3=146097;//格里高利历中每400年的天数
const int N4=6299-10;
//从1582.10.3快进到1600.1.1的天数,注意有10天被删掉了
const int N5=36524;//格里高利历每100年的天数
const int N6=1461;//格里高利历每4年的天数
const int mon1[]={0,31,28,31,30,31,30,31,31,30,31,30,31};//平年月份
const int mon2[]={0,31,29,31,30,31,30,31,31,30,31,30,31};//闰年月份
void solve1(long long r);//不到达转换格里高利历时间做法
void solve2(long long r);//转换到了格里高利历做法
inline bool run1(long long y)//儒略历闰年判断函数
{
if(y<0)//注意还要判正负
++y;
if(y%4==0)return true;
else return false;
}
inline bool run2(long long y)//格里高利历闰年判断函数
{
if((y%4==0&&y%100!=0)||y%400==0)return true;
return false;
}
int main()
{
//freopen("julian3.in","r",stdin);
//freopen("dabiaoo.txt","w",stdout);
int Q;
cin>>Q;
for(int i=1;i<=Q;++i)
{
long long r;
cin>>r;
if(r<=N1)solve1(r);//不到达转换格里高利历时间做法
else solve2(r);//转换到了格里高利历做法
}
return 0;
}
void solve1(long long r)
{
long long n1=r/N2;//求出有多少个4年
r%=N2;//剩余天数
long long y=n1*4-4713,m=1,d=1;//求出未加剩余天数的日期
if(y>0)++y;//公元零年并不存在
//cout<<r<<endl;
for(;r>=365;++y)
{
if(run1(y)&&r>=366)//如果此时是闰年
r-=366;
else r-=365;
}
//cout<<r<<endl;
if(run1(y))//如果此时是闰年
{
for(;r-mon2[m]>0;++m)r-=mon2[m];
}
else for(;r-mon1[m]>0;++m)r-=mon1[m];
d+=r;
if(y>0)printf("%d %d %d\n",d,m,y);
else printf("%d %d %d BC\n",d,m,-y);
}
void solve2(long long r)
{
long long y=0,m=0,d=0;
r-=N1,y=1582,m=10,d=3;//快进到1582.10.3
if(r>=N4)r-=N4,y=1600,m=1,d=1;//如果天数允许,快进到1600.1.1
//cout<<r<<endl;
long long n1=r/N3;//算出r中有多少个400年
r%=N3;//求出剩余天数
y+=n1*400;
//cout<<r<<endl;
for(;r>=N5;)
{
if(run2(y)&&r>=N5+1)
r=r-N5-1,y+=100;
else if (run2(y)&&r<N5+1)break;
else r-=N5,y+=100;
}
//cout<<r<<endl;
if(r>N6)
{
int n2=r/N6;
y+=n2*4;
r%=N6;
++r;
//cout<<r<<endl;
}
for(;r>=365;)
{
if(run2(y)&&r>=366)//如果此时是闰年
r-=366,++y;
else if(run2(y)&&r<366)break;
else r-=365,++y;
}
//cout<<r<<endl;
if(run2(y))//如果此时是闰年
{
for(;r-mon2[m]>=0;++m)r-=mon2[m];
}
else for(;r-mon1[m]>=0;++m)r-=mon1[m];
//cout<<r<<endl;
d+=r;
printf("%d %d %d\n",d,m,y);
}
这道题我已经调了整整两天还是没过
感谢指教!