Robin Hood and the Major Oak

jumaoxiangrijui / 2024-10-23 / 原文

题目链接:
https://codeforces.com/contest/2014/problem/B
题解:

  • 因为树叶的寿命为k;所以在第n年的时候前n-k年的树叶都没了,就从n-k开始算就行,但要注意,如果k>n时,就得把每年都算上去了,不能直接用n-k;所以需要添加一个判断条件。
  • 第二个方面就是判断是否为偶数,直接用i^i连longlong都保不住你,所以采用求余替换(毕竟它只要求判断奇偶);再按照奇奇得偶,奇偶为奇,偶偶是偶的运算法则,将所需年份历遍就行,这里我还判断了第n年是奇还是偶,看起来会清晰些。

代码

#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		int m = 0;
		int s;
		if (n - k >= 0)
			s = k-1;
		else
			s = 0;
		if (n % 2 == 0) {
			if (s % 4 == 0||s%4==3)
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
		else {
			if (s % 4 == 0||s%4==1)
				cout << "NO" << endl;
			else
				cout << "YES" << endl;
		}
    }
}