本蒟蒻写的代码中,958153104的答案是12.31,而正解是12.30,调了一天了都没看出问题,求调!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string.h>
#define LL long long
using namespace std;
int T;
LL n;
int Month_Day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int sum[410];
void Get(LL n,LL &Month,LL &Day,bool Is_Leap_Year){
LL ans=0;
for(int i=1;i<=12;i++){
if(Is_Leap_Year&&i==2){
if(ans+Month_Day[i]+1>n){
Month=i;
Day=n-ans;
return ;
}
ans+=Month_Day[i]+1;
if(ans==n){
Month=i;
Day=Month_Day[i]+1;
return ;
}
continue;
}
if(ans+Month_Day[i]>n){
Month=i;
Day=n-ans;
return ;
}
ans+=Month_Day[i];
if(ans==n){
Month=i;
Day=Month_Day[i];
return ;
}
}
return ;
}
bool Check(int Year){
return Year%4==0&&Year%100!=0||Year%400==0;
}
LL Find(LL &n){
int l=0,r=400;
while(l<r){
int mid=(l+r+1)>>1;
if(sum[mid]<=n)
l=mid;
else
r=mid-1;
}
if(n!=sum[l]){
n=n-sum[l];
return l;
}else{
n=n-sum[l-1];
return l-1;
}
}
void Solve(){
LL Year=0,Month=0,Day=0;
scanf("%lld",&n);n++;
if(n<=1721424){
LL t=n/1461;
if(n%1461==0){
Year=4713-t*4+1;
Month=12;
Day=31;
}else{
n-=t*1461;
Year=4713-t*4;
if(n<=366)
Get(n,Month,Day,true);
else if(n<=366+365)
Get(n-366,Month,Day,false),Year-=1;
else if(n<=366+365+365)
Get(n-366-365,Month,Day,false),Year-=2;
else
Get(n-366-365-365,Month,Day,false),Year-=3;
}
printf("%lld %lld %lld BC\n",Day,Month,Year);
}else if(n<=2299161){
n-=1721424;
LL t=n/1461;
if(n%1461==0){
Year=t*4;
Month=12;
Day=31;
}else{
n-=t*1461;
Year=t*4+1;
if(n<=365)
Get(n,Month,Day,false);
else if(n<=365+365)
Get(n-365,Month,Day,false),Year+=1;
else if(n<=365+365+365)
Get(n-365-365,Month,Day,false),Year+=2;
else
Get(n-365-365-365,Month,Day,true),Year+=3;
}
printf("%lld %lld %lld\n",Day,Month,Year);
}else{
n-=2299161;
if(n<=78){
Year=1582;
if(n<=17){
Month=10;
Day=n+14;
}else if(n<=47){
Month=11;
Day=n-17;
}else{
Month=12;
Day=n-47;
}
}else{
n-=78;
LL t=n/146097;
n%=146097;
Year=1583+t*400;
if(n==0){
Month=12;
Day=31;
}else{
Year+=Find(n);
Get(n,Month,Day,Check(Year));
}
}
printf("%lld %lld %lld\n",Day,Month,Year);
}
return ;
}
void Init(){
for(int i=1573;i<=1573+400-1;i++)
if(Check(i))
sum[i-1572]=sum[i-1573]+366;
else
sum[i-1572]=sum[i-1573]+365;
return ;
}
int main(){
Init();
scanf("%d",&T);
while(T--)
Solve();
printf("\n");
return 0;
}
第 118 行到第 146 行是 958153104 时的求解。