记录编号 581361 评测结果 AAAAAAAAAA
题目名称 [CSP 2020S]儒略日 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 0.204 s
提交时间 2023-08-01 22:57:11 内存使用 2.87 MiB
显示代码纯文本
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//神秘のO(12)模拟算法 
ll n;
ll s;//不开longlong会爆掉 
ll p[20] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
ll r[20] = {0,31,29,31,30,31,30,31,31,30,31,30,31};//初始化
ll x1 = 1721424,x2 = 2299161; //x1为公元前后的分界,x2为消失の10天的分界 
ll chu(ll x,ll y){
	if(x % y == 0)return (x / y) - 1;
	return x / y;
};//整除 
ll mo(ll x,ll y){
	if(x % y == 0)return y;
	return x % y;
}//除余 
void BC();
void BC_();
int main(){
    freopen("2020julian.in","r",stdin);
    freopen("2020julian.out","w",stdout);
    for(int i = 1;i <= 12;i++){
        p[i] += p[i-1];
        r[i] += r[i-1];
    }
    scanf("%d",&n);
    for(ll j = 1;j <= n;j++){
        scanf("%lld",&s);
        s++;
        //cout<<s<<endl;
        if(s <= x1){
        	BC();
        	continue;//公元前 
        }
        else if(s <= x2){
        	BC_();
        	continue;//公元1年至消失の10天; 
        }
		//消失の10天 
        else{
            s = s - x2 + 277 + 10;//加上消失の10天
            //从1582年1月1日开始; 
            if(s <= 730){
            	ll year = chu(s,365),day = mo(s,365);
            	for(int i = 1;i <= 12;i++){
            		if(day <= p[i]){
            			printf("%d %d %d\n",day-p[i-1],i,1582+year);
            			break;
					}
				}
				continue;
			}//特判1582和1583年 
			else if(s <= 6574){
				s -= 730;
				ll year4 = chu(s,1461),day = mo(s,1461);//润平平平 
				if(day <= 366){
        			for(int i = 1;i <= 12;i++)
            			if(day <= r[i]){
                			printf("%d %d %d\n",day-r[i-1],i,1584+4*year4);
							break;
            			}
    			}
    			else{
        			ll year1 = chu(day-366,365);day = mo(day-366,365);
        			for(int i = 1;i <= 12;i++){
            			if(day <= p[i]){
                			printf("%d %d %d\n",day-p[i-1],i,1584+4*year4+year1+1);
                			break;
            			}
        			}
    			}
			}//1584至1599年 
			else if(s <= 6940){
				s -= 6574;
				for(int i = 1;i <= 12;i++){
					if(s <= r[i]){
						printf("%d %d 1600\n",s-r[i-1],i);
						break;
					}
				}
			}//特判1600年 
			else{
				s -= 6940;//从1601年开始
				ll year400 = chu(s,146097),day = mo(s,146097);//分四百年 
				if(day <= 109572){//前三百年 
					ll year100 = chu(day,36524);day = mo(day,36524);
					if(day <= 35064){//每百年的前96年 
						ll year4 = chu(day,1461);day = mo(day,1461);//以平平平润为顺序
						if(day <= 1095){ 
							ll year = chu(day,365);day = mo(day,365);
							for(int i = 1;i <= 12;i++){
								if(day <= p[i]){
									printf("%d %d %d\n",day-p[i-1],i,1600+year400*400+year100*100+year4*4+year+1);
								    break;
								}
							}
						}//前三个平年 
						else{//闰年 
							day -= 1095;
							for(int i = 1;i <= 12;i++){
								if(day <= r[i]){
									printf("%d %d %d\n",day-r[i-1],i,1600+year400*400+year100*100+year4*4+4);
									break;
								}
							}
						}
					}
					else{//后四年都为平年 
						day -= 35064;
						ll year = chu(day,365);day = mo(day,365);
						for(int i = 1;i <= 12;i++){
							if(day <= p[i]){
								printf("%d %d %d\n",day-p[i-1],i,1696+year400*400+year100*100+year+1);
								break;
							}
						}
					}
				}
				else{//后一百年 
				    day -= 109572;//┭┮﹏┭┮打成109527调试了20min; 
					ll year4 = chu(day,1461);day = mo(day,1461);//所有顺序都为平平平润 
					if(day <= 1095){
						ll year = chu(day,365);day = mo(day,365);
						for(int i = 1;i <= 12;i++){
							if(day <= p[i]){
								printf("%d %d %d\n",day-p[i-1],i,1600+400*year400+300+4*year4+year+1);
								break;
							}
						}
					}//前三个平年 
					else{//闰年 
						day -= 1095;
						for(int i = 1;i <= 12;i++){
							if(day <= r[i]){
								printf("%d %d %d\n",day-r[i-1],i,1600+400*year400+300+4*year4+4);
								break;
							}
						}
					}
				} 
			}
        }
    }
    
    return 0;
    
}
void BC_(){
	ll year4 = chu(s-x1,1461),day = mo(s-x1,1461);//平平平润 
    if(day <= 1095){
        ll year = chu(day,365);day = mo(day,365);
        for(int i = 1;i <= 12;i++){
            if(day <= p[i]){
                printf("%d %d %d\n",day-p[i-1],i,year4*4+year+1);
                break;
            }
        }
    }
    else{
        day -= 1095;
        for(int i = 1;i <= 12;i++){
            if(day <= r[i]){
                printf("%d %d %d\n",day-r[i-1],i,year4*4+4);
                break;
            }
        }
    }
    return;
}
void BC(){
	ll year = chu(s,1461),day = mo(s,1461);//以润平平平为顺序 
    if(day <= 366){
        for(int i = 1;i <= 12;i++)
            if(day <= r[i]){
                printf("%d %d %d BC\n",day-r[i-1],i,4713-4*year);
				break;
            }
    }
    else{
        ll year1 = chu(day-366,365);day = mo(day-366,365);
        for(int i = 1;i <= 12;i++){
            if(day <= p[i]){
                printf("%d %d %d BC\n",day-p[i-1],i,4713-4*year-(year1+1));
                break;
            }
        }
    }
    return;
}