关于常数
  • 板块学术版
  • 楼主Remake_
  • 当前回复2
  • 已保存回复2
  • 发布时间2020/11/7 21:30
  • 上次更新2023/11/5 08:34:31
查看原帖
关于常数
223797
Remake_楼主2020/11/7 21:30

这是蒟蒻今天T1的代码,应该是正确的,复杂度也是O(1)O(1)的,但是常数超大,请问能不能过?(对拍和样例都过了)

代码

#include<bits/stdc++.h>
using namespace std;
long long T,k,tmp1,tmp2,Y,tmp3,tmp4,pos;
long long over;
long long dayssim[15]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
long long daysrun[15]= {0,31,29,31,30,31,30,31,31,30,31,30,31};
long long pre[405];
bool isrun(long long x) {
	return x%400==0||(x%4==0&&x%100!=0);
}
int main() {
	freopen("julian.in","r",stdin);
	freopen("julian.out","w",stdout);
	for(int i=1; i<=400; i++) isrun(i+1582)?pre[i]=pre[i-1]+366:pre[i]=pre[i-1]+365;
	cin>>T;
	while(T--) {
		over=1;
		cin>>k;
		++k;
		tmp1=k%1461;
		tmp2=k/1461;
		Y=4713-tmp2*4;
		if(k<1721424) {
			for(int i=1; i<=12&&over; i++) {
				if(tmp1<=daysrun[i]) {
					cout<<tmp1<<' '<<i<<' '<<Y<<" BC"<<endl;
					over=0;
				} else tmp1-=daysrun[i];
			}
			--Y;
			for(int i=1; i<=12&&over; i++) {
				if(tmp1<=dayssim[i]) {
					cout<<tmp1<<' '<<i<<' '<<Y<<" BC"<<endl;
					over=0;
				} else tmp1-=dayssim[i];
			}
			--Y;
			for(int i=1; i<=12&&over; i++) {
				if(tmp1<=dayssim[i]) {
					cout<<tmp1<<' '<<i<<' '<<Y<<" BC"<<endl;
					over=0;
				} else tmp1-=dayssim[i];
			}
			--Y;
			for(int i=1; i<=12&&over; i++) {
				if(tmp1<=dayssim[i]) {
					cout<<tmp1<<' '<<i<<' '<<Y<<" BC"<<endl;
					over=0;
				} else tmp1-=dayssim[i];
			}
		} else {
			if(k<=2299160) {
				//k-=1721058;
				k-=1721424;
				tmp1=k%1461+1;
				tmp2=k/1461;
				Y=tmp2*4+1;
				for(int i=1; i<=12&&over; i++) {
					if(tmp1<=daysrun[i]) {
						cout<<tmp1<<' '<<i<<' '<<Y<<endl;
						over=0;
					} else tmp1-=daysrun[i];
				}
				++Y;
				for(int i=1; i<=12&&over; i++) {
					if(tmp1<=dayssim[i]) {
						cout<<tmp1<<' '<<i<<' '<<Y<<endl;
						over=0;
					} else tmp1-=dayssim[i];
				}
				++Y;
				for(int i=1; i<=12&&over; i++) {
					if(tmp1<=dayssim[i]) {
						cout<<tmp1<<' '<<i<<' '<<Y<<endl;
						over=0;
					} else tmp1-=dayssim[i];
				}
				++Y;
				for(int i=1; i<=12&&over; i++) {
					if(tmp1<=dayssim[i]) {
						cout<<tmp1<<' '<<i<<' '<<Y<<endl;
						over=0;
					} else tmp1-=dayssim[i];
				}
			} else {
				k-=2299161;
				if(k<=78) {
					if(k<=17) cout<<14+k<<" 10 1582"<<endl;
					else if(k<=47) cout<<k-17<<" 11 1582"<<endl;
					else if(k<=78) cout<<k-47<<" 12 1582"<<endl;
				} else {
					k-=78;
					tmp3=k/146097,tmp4=k%146097;
					Y=1583+400*tmp3;
					pos=upper_bound(pre+1,pre+401,tmp4)-pre-1;
					Y+=pos;
					tmp4-=pre[pos];
					if(isrun(Y)) {
						for(int i=1; i<=12&&over; i++) {
							if(tmp4<=daysrun[i]) {
								cout<<tmp4<<' '<<i<<' '<<Y<<endl;
								over=0;
							} else tmp1-=daysrun[i];
						}
					} else {
						for(int i=1; i<=12&&over; i++) {
							if(tmp4<=dayssim[i]) {
								cout<<tmp4<<' '<<i<<' '<<Y<<endl;
								over=0;
							} else tmp4-=dayssim[i];
						}
					}
				}
			}
		}
	}
	return 0;
}
2020/11/7 21:30
加载中...