Day11-G - Calendar Game HDU - 1079
A player wins the game when he/she exactly reaches the date of November 4, 2001. If a player moves to a date after November 4, 2001, he/she looses the game.
Write a program that decides whether, given an initial date, Adam, the first mover, has a winning strategy.
For this game, you need to identify leap years, where February has 29 days. In the Gregorian calendar, leap years occur in years exactly divisible by four. So, 1993, 1994, and 1995 are not leap years, while 1992 and 1996 are leap years. Additionally, the years ending with 00 are leap years only if they are divisible by 400. So, 1700, 1800, 1900, 2100, and 2200 are not leap years, while 1600, 2000, and 2400 are leap years.
InputThe input consists of T test cases. The number of test cases (T) is given in the first line of the input. Each test case is written in a line and corresponds to an initial date. The three integers in a line, YYYY MM DD, represent the date of the DD-th day of MM-th month in the year of YYYY. Remember that initial dates are randomly chosen from the interval between January 1, 1900 and November 4, 2001.
OutputPrint exactly one line for each test case. The line should contain the answer "YES" or "NO" to the question of whether Adam has a winning strategy against Eve. Since we have T test cases, your program should output totally T lines of "YES" or "NO".
Sample Input
3
2001 11 3
2001 11 2
2001 10 3
Sample Output
YES
NO
NO 如果要SG打表,对闰年的处理太困难,就需要忽略年份,那我们可以选择只考虑日期和月份,可以从奇偶性来考虑,先将日期转移情况列出来:
现在日期是(m, d)
1.日期加一 m+(d+1)
2.月份加一 (m+1)+d
3.到新的一个月 (m+1)+1
若m+d和为偶数时,操作1与2后和变为奇数,只满足操作3,不满足操作1、2的数对有(1,31)(3,31)(5,31)(8,31)(10,31),其中满足和为偶数的有(1,31)(3,31)(5,31),所以可以断言,所有和为偶数的数对都可以变成奇数
若m+d和为奇数时,操作1与2后和变为偶数,能满足操作3的数有(1,31)(2,28/29)(3,31)(4,30)(5,31)(6,30)(7,31)(8,31)(9,30)(10,31)(11,30)(12,31),其中和为奇数的有(2,29)(8,31)(9,30)(10,31)(11,30)(12,31),其中操作后为奇数的只有(9,30)(11,30)
已知目标状态为11+4=15,是奇数,那么,谁最终状态是奇数就必败,所以先手是偶数或者(9,30)(11,30)的时候就可以将奇数给后手,后手必定只能传递偶数回来,如果后手也拿到了(9,30)(11,30)呢?先手可以用最佳手段避开,两者的前者状态分别为(8,30)(9,29)(10,30)(11,29),这些都是偶数,可以有其他办法转移到其他奇数给后手
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL; void run_case() {
int year, month, day;
cin >> year >> month >> day;
if((month+day)%==||(month==&&day==)||(month==&&day==)) cout << "YES\n";
else cout << "NO\n";
} int main() {
ios::sync_with_stdio(false), cin.tie();
int t; cin >> t;
while(t--)
run_case();
cout.flush();
return ;
}
最新文章
- Rafy 框架 - 执行SQL或存储过程
- 【转】SqlServer将没有log文件的数据库文件附加到服务器中
- Eclipse Memory Analyzer,内存泄漏插件,安装使用一条龙
- CSS3 box-flex属性和box-orient属性
- DTD Tutorial
- HTTP 错误 500.21 - Internal Server Error的解决方案
- 本地代码git到github上
- Android项目---HtmlParse
- yii2.0使用ActionForm创建表单
- Kotlin实现LeetCode算法题之Median of Two Sorted Arrays
- 时间戳转换成时间js(年-月-日,例如“2017-04-22”)
- 不能忽视 php warning
- Python复习笔记(十一)TCP/IP协议
- 压力(性能)测试及jmeter的使用
- JavaScript面向对象--记录防忘记(一)
- TCP/IP的分层管理
- nowcoder172C 保护 (倍增lca+dfs序+主席树)
- Curl工具的使用
- 依赖注入(DI)和控制反转(IOC)的理解,写的太好了。
- 下拉菜单;手风琴;九宫格的Jquery的使用实例