Loading

「学习笔记」模拟

模拟,简单说就是题目让你干什么你就干什么,你要模拟它的过程
模拟题很考验代码能力你是否是合格的码农,但是如果考试考到,没有百分之百的把握,就不要去对着正解死磕!打好部分分走人就行了!


那这道题举例子
[CSP-S2020] 儒略日
这是当年的一道模拟题,今天,它花了我一整个白天加 \(20\) 分钟晚自习的时间,在 \(\text{luogu}\) 过了后还被 \(\text{cjx}\) 卡掉了,原因:多加了一个 \(=\)(%%% \(\text{cjx}\)),能做出这道题来真的很有成就感,因为没看题解,所以代码敲了 \(457\) 行,但是还是说,如果考场上碰到模拟,拿上部分分就走人就行了
思路:将时间轴按照历法分成两段,前一段为儒略历,后一段(至未来)是格里高利历,然后,我就进行了纯模拟不然为什么代码这么长

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define bug puts("NOIP AK ME!");

const int pmon[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int rmon[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int bcy[5] = {0, 366, 365, 365, 365};
const int y[5] = {0, 365, 365, 365, 366};

ll Q, n;
int psum[13], rsum[13], bcysum[5], ysum[5];

void work_ymd_run(ll year, ll month, ll day, ll n, bool ok) {
	if (n <= rsum[6]) {
		if (n > rsum[5])	month = 6, day = n - rsum[5];
		else if (n > rsum[4])	month = 5, day = n - rsum[4];
		else if (n > rsum[3])	month = 4, day = n - rsum[3];
		else if (n > rsum[2])	month = 3, day = n - rsum[2];
		else if (n > rsum[1])	month = 2, day = n - rsum[1];
		else month = 1, day = n;
	}
	else {
		if (n > rsum[11])	month = 12, day = n - rsum[11];
		else if (n > rsum[10])	month = 11, day = n - rsum[10];
		else if (n > rsum[9])	month = 10, day = n - rsum[9];
		else if (n > rsum[8])	month = 9, day = n - rsum[8];
		else if (n > rsum[7])	month = 8, day = n - rsum[7];
		else month = 7, day = n - rsum[6];
	}
	printf("%lld %lld %lld ", day, month, year);
	if (ok)	puts("BC");
	else	puts("");
	return ;
}

void work_ymd_ping(ll year, ll month, ll day, ll n, bool ok) {
	if (n <= psum[6]) {
		if (n > psum[5])	month = 6, day = n - psum[5];
		else if (n > psum[4])	month = 5, day = n - psum[4];
		else if (n > psum[3])	month = 4, day = n - psum[3];
		else if (n > psum[2])	month = 3, day = n - psum[2];
		else if (n > psum[1])	month = 2, day = n - psum[1];
		else month = 1, day = n;
	}
	else {
		if (n > psum[11])	month = 12, day = n - psum[11];
		else if (n > psum[10])	month = 11, day = n - psum[10];
		else if (n > psum[9])	month = 10, day = n - psum[9];
		else if (n > psum[8])	month = 9, day = n - psum[8];
		else if (n > psum[7])	month = 8, day = n - psum[7];
		else month = 7, day = n - psum[6];
	}
	printf("%lld %lld %lld ", day, month, year);
	if (ok)	puts("BC");
	else	puts("");
	return ;
}

void rlr(ll year, ll month, ll day) {
	if (n < 1721424) {
		int g = n / bcysum[4], res = n % bcysum[4];
		year -= g * 4;
		if (res == 0) {
			++ year;
			printf("31 12 %lld BC\n", year);
			return ;
		}
		if (res <= bcysum[1]) {
			day = res;
			if (year % 4 == 1) {
				work_ymd_run(year, 1, 1, day, 1);
			}
			else	work_ymd_ping(year, 1, 1, day, 1);
		}
		else if (res <= bcysum[2]) {
			-- year, day = res - bcysum[1];
			if (year % 4 == 1) {
				work_ymd_run(year, 1, 1, day, 1);
			}
			else	work_ymd_ping(year, 1, 1, day, 1);
		}
		else if (res <= bcysum[3]) {
			year -= 2, day = res - bcysum[2];
			if (year % 4 == 1) {
				work_ymd_run(year, 1, 1, day, 1);
			}
			else	work_ymd_ping(year, 1, 1, day, 1);
		}
		else {
			year -= 3, day = res - bcysum[3];
			if (year % 4 == 1) {
				work_ymd_run(year, 1, 1, day, 1);
			}
			else	work_ymd_ping(year, 1, 1, day, 1);
		}
	}
	else if (n == 1721424) {
		printf("31 12 1 BC\n");
	}
	else {
		year = 1;
		n -= 1721424;
		int g = n / ysum[4], res = n % ysum[4];
		year += g * 4;
		if (res == 0) {
			printf("31 12 %lld\n", year - 1);
			return ;
		}
		if (res <= ysum[1]) {
			day = res;
			if (year % 4 == 0) {
				work_ymd_run(year, 1, 1, day, 0);
			}
			else	work_ymd_ping(year, 1, 1, day, 0);
		}
		else if (res <= ysum[2]) {
			++ year, day = res - ysum[1];
			if (year % 4 == 0) {
				work_ymd_run(year, 1, 1, day, 0);
			}
			else	work_ymd_ping(year, 1, 1, day, 0);
		}
		else if (res <= ysum[3]) {
			year += 2, day = res - ysum[2];
			if (year % 4 == 0) {
				work_ymd_run(year, 1, 1, day, 0);
			}
			else	work_ymd_ping(year, 1, 1, day, 0);
		}
		else {
			year += 3, day = res - ysum[3];
			if (year % 4 == 0) {
				work_ymd_run(year, 1, 1, day, 0);
			}
			else	work_ymd_ping(year, 1, 1, day, 0);
		}
	}
}

void workglgl(ll year, ll month, ll day, ll n, bool ok) {
	int g = n / 146097, res = n % 146097;
	if (res == 0) {
		year += (g * 400 - 1);
		printf("31 12 %lld\n", year);
		return ;
	}
	year += g * 400;
	if (res <= 36524) {
		int gg = res / ysum[4], re = res % ysum[4];
		if (re == 0) {
			printf("31 12 %lld\n", year + gg * 4 - 1);
			return ;
		}
		year += gg * 4;
		if (re <= ysum[1]) {
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else if (re <= ysum[2]) {
			year ++;
			re -= ysum[1];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else if (re <= ysum[3]) {
			year += 2;
			re -= ysum[2];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else {
			year += 3;
			re -= ysum[3];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
	}
	else if (res <= 73048) {
		year += 100;
		res -= 36524;
		int gg = res / ysum[4], re = res % ysum[4];
		if (re == 0) {
			printf("31 12 %lld\n", year + gg * 4 - 1);
			return ;
		}
		year += gg * 4;
		if (re <= ysum[1]) {
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else if (re <= ysum[2]) {
			year ++;
			re -= ysum[1];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else if (re <= ysum[3]) {
			year += 2;
			re -= ysum[2];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else {
			year += 3;
			re -= ysum[3];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
	}
	else if (res <= 109572) {
		year += 200;
		res -= 73048;
		int gg = res / ysum[4], re = res % ysum[4];
		if (re == 0) {
			printf("31 12 %lld\n", year + gg * 4 - 1);
			return ;
		}
		year += gg * 4;
		if (re <= ysum[1]) {
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else if (re <= ysum[2]) {
			year ++;
			re -= ysum[1];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else if (re <= ysum[3]) {
			year += 2;
			re -= ysum[2];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else {
			year += 3;
			re -= ysum[3];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
	}
	else {
		year += 300;
		res -= 109572;
		int gg = res / ysum[4], re = res % ysum[4];
		if (re == 0) {
			printf("31 12 %lld\n", year + gg * 4 - 1);
			return ;
		}
		year += gg * 4;
		if (re <= ysum[1]) {
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else if (re <= ysum[2]) {
			year ++;
			re -= ysum[1];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else if (re <= ysum[3]) {
			year += 2;
			re -= ysum[2];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
		else {
			year += 3;
			re -= ysum[3];
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, re, 0);
			}
			else {
				work_ymd_ping(year, month, day, re, 0);
			}
		}
	}
}

void glgl(ll year, ll month, ll day) {
	if (n <= 16) {
		day += n;
		printf("%lld %lld %lld\n", day, month, year);
	}
	else if (n <= 46) {
		day = n - 16;
		++ month;
		printf("%lld %lld %lld\n", day, month, year);
	}
	else if (n <= 77) {
		day = n - 46;
		month += 2;
		printf("%lld %lld %lld\n", day, month, year);
	}
	else if (n <= 808){
		n -= 77, month = day = 1, year ++;
		if (n <= 365) {
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, n, 0);
			}
			else {
				work_ymd_ping(year, month, day, n, 0);
			}
		}
		else {
			n -= 365, year ++;
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
				work_ymd_run(year, month, day, n, 0);
			}
			else {
				work_ymd_ping(year, month, day, n, 0);
			}
		}
	}
	else {
		n -= 808, year = 1585;
		if (n <= 4 * ysum[4]) {
			int g = n / ysum[4], res = n % ysum[4];
			if (res == 0) {
				printf("31 12 %lld", year + g * 4 - 1);
				return ;
			}
			year += g * 4;
			if (res <= ysum[1]) {
				if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
					work_ymd_run(year, month, day, res, 0);
				}
				else {
					work_ymd_ping(year, month, day, res, 0);
				}
			}
			else if (res <= ysum[2]) {
				year ++;
				res -= ysum[1];
				if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
					work_ymd_run(year, month, day, res, 0);
				}
				else {
					work_ymd_ping(year, month, day, res, 0);
				}
			}
			else if (res <= ysum[3]) {
				year += 2;
				res -= ysum[2];
				if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
					work_ymd_run(year, month, day, res, 0);
				}
				else {
					work_ymd_ping(year, month, day, res, 0);
				}
			}
			else {
				year += 3;
				res -= ysum[3];
				if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
					work_ymd_run(year, month, day, res, 0);
				}
				else {
					work_ymd_ping(year, month, day, res, 0);
				}
			}
		}
		else {
			workglgl(1601, 1, 1, n - 4 * ysum[4], 0);
		}
	}
}

void work() {
	if (n < 2299162) {
		rlr(4713, 1, 1);
		return ;
	}
	else {
		n -= 2299162;
		glgl(1582, 10, 15);
	}
}

int main() {
	for (int i = 1; i <= 5; ++ i) {
		bcysum[i] = bcysum[i - 1] + bcy[i];
		ysum[i] = ysum[i - 1] + y[i];
	}
	for (int i = 1; i <= 12; ++ i) {
		psum[i] = psum[i - 1] + pmon[i];
		rsum[i] = rsum[i - 1] + rmon[i];
	}
	scanf("%lld", &Q);
	for (int i = 1; i <= Q; ++ i) {
		scanf("%lld", &n);
		++ n;
		work();
	}
	return 0;
}
posted @ 2023-02-26 20:09  yi_fan0305  阅读(28)  评论(0编辑  收藏  举报