Calendar Game POJ - 1082(关于日历的博弈问题)

题意:

两个人轮流玩游戏,每个人可以把日期进行转移,转移规则:
1.可以转移到当前日期的下一天。
2可以转移到下个月的这一天。(但是如果下个月没有这一天就不能进行第二种转移)
3.如果A恰好移动到2001.11.4那么A赢,如果移动到2001.11.4之后则输给你初始日期(只能在1900.1.1~2001.11.4)求先移动的人的胜负态

题目:

Adam and Eve enter this year’s ACM International Collegiate Programming Contest. Last night, they played the Calendar Game, in celebration of this contest. This game consists of the dates from January 1, 1900 to November 4, 2001, the contest day. The game starts by randomly choosing a date from this interval. Then, the players, Adam and Eve, make moves in their turn with Adam moving first: Adam, Eve, Adam, Eve, etc. There is only one rule for moves and it is simple: from a current date, a player in his/her turn can move either to the next calendar date or the same day of the next month. When the next month does not have the same day, the player moves only to the next calendar date. For example, from December 19, 1924, you can move either to December 20, 1924, the next calendar date, or January 19, 1925, the same day of the next month. From January 31 2001, however, you can move only to February 1, 2001, because February 31, 2001 is invalid.

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.

Input

The input consists of T test cases. The number of test cases (T ) is given in the first line of the input file. 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.

Output

Print 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

分析:

这是一条简单的规律:一般情况下,月份和日子同奇偶则必胜,否则必败;只有9月30和11月30是例外。

有31天的月份:1,3,5,7,8,10,12
30天的月份:4,6,9,11
奇葩月:2
(1).先从2001.11开始看,这个月只有4天,且每一天只有第一种转移态,那么可以知道1和3号是必胜态,2和4号是必败态,故2001.11月是奇胜
(2).再向前看10月,因为10.5~ 10.31的转移态只有第一种转移态,那么根据推断,10.31为必败,所以5 ~ 31的这些天里偶数的天为必胜态,奇数必败。再看10月的1 ~ 4,对于4来说下一个可以到5和11.4,所以必胜,对于3可以到11.3和10.4所以必败,所以1~4也是偶数必胜奇数必败,故10月是偶数必胜,奇数必败
(3).再看9月,因为9.30可以转到10.1和10.30,为了胜利就选择到10.1故9.30必胜,然后看9.29,可以转到10.29和9.30,同样为了胜利转到10.29,但是再看9.28,无论转到9.29还是10.28都会输,所以9.28是必败,同理9月的1~ 27都是奇胜偶败,加上28,29,30可以得出结论,9月的1~29号都是奇胜偶败,且9.30也为胜。
(4).再看八月,8.31只能到9.1,故为败,8.30可以到8.31故为胜,8.29可以到9.29和8.30,而这两种都会输,所以8.29是输,则1~28号的推理过程相似所以8月是奇败偶胜
这样可以按照相同的方法推出:
(5).7月:奇胜偶败
。。。。。。。
3月:奇胜偶败
再来看2月,如果有29天,则对于2.29可以到3.29和3.1,都会输,所以2.29败,2.28可以到2.29故会赢。所以这种情况是奇败偶胜
如果只有28天,2.28可以到3.28故会赢,2.27可以到2.28和3.27,但都会输,所以这种情况是奇败偶胜
所以2月无论是有29天还是有28天都是奇败偶胜
1月:奇胜偶败
前一年:
12月:奇败偶胜
11月:30可以到12.1,所以胜利,29可以到12.29所以胜利,28可以到29和12.28,但是都会输,所以11月的1~29都是奇胜偶败,且30也会胜利
所以对于任意一个日期(除了9.30和11.30)只要月份+天数为偶数就会胜利,否则失败。

AC代码:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int t,n,m,k;
int main(){cin>>t;while(t--){cin>>n>>m>>k;if(m==9&&k==30||m==11&&k==30)cout<<"YES"<<endl;else if((m+k)%2==0)cout<<"YES"<<endl;else cout<<"NO"<<endl;}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/309524.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[Java基础]JDK内置注解

示例代码如下: package annotation;SuppressWarnings("all") public class AnnoDemo2 {Overridepublic String toString(){return super.toString();}Deprecatedpublic void show(){//有缺陷}public void show1(){//替代show方法}public void demo(){show();}}

学了这么多年精益思想,居然不知道还有第八种浪费 | IDCF

价值和浪费“我是彻底的现场主义者。与其在领导办公室内冥思苦想&#xff0c;倒不如到生产现场的各个角落&#xff0c;直接获得第一手的生产信息和感受直接的刺激。”——大野耐一&#xff0c;丰田生产方式之父大野耐一提倡直接去现场工作&#xff0c;在那里才能看到价值与浪费…

41 sysfs 文件系统

前言 在 linux 中常见的文件系统 有很多, 如下 基于磁盘的文件系统, ext2, ext3, ext4, xfs, btrfs, jfs, ntfs 内存文件系统, procfs, sysfs, tmpfs, squashfs, debugfs 闪存文件系统, ubifs, jffs2, yaffs 文件系统这一套体系在 linux 有一层 vfs 抽象, 用户程序不用…

A Greeting from Qinhuangdao Gym - 102769A 2020ccpc秦皇岛分站赛

题意&#xff1a; 给你n个红球和m个蓝色球。然后以相等的概率随机选择了其中两个。选择两个红球的概率是多少&#xff1f; 题目&#xff1a; Welcome to the CCPC Qinhuangdao Site! Qinhuangdao is a beautiful coastal city full of charm, integrating historical herit…

Gartner:6个容器和Kubernetes策略的最佳实用技巧

导语采用容器和Kubernetes要求整个企业保持一致&#xff0c;不了解这些前期现实会导致一些非常严峻的后果。正文Gartner估计&#xff0c;到2022年&#xff0c;将有75&#xff05;的组织在生产中运行容器化应用程序。毫无疑问&#xff0c;Kubernetes已成为组织容器的流行方法。通…

[JavaWeb-MySQL]约束(非空约束,唯一约束,主键约束,外键约束_级联操作)

约束 * 概念&#xff1a; 对表中的数据进行限定&#xff0c;保证数据的正确性、有效性和完整性。 * 分类&#xff1a;1. 主键约束&#xff1a;primary key2. 非空约束&#xff1a;not null3. 唯一约束&#xff1a;unique4. 外键约束&#xff1a;foreign key* 非空约束&#x…

Friendly Group Gym - 102769F 2020(并查集)ccpc秦皇岛分站赛

题意&#xff1a; n个学生要组成一个小组参加会议&#xff08;可以不参加&#xff09;&#xff0c; 1.对于每两个朋友&#xff08;x &#xff0c;y)&#xff0c;如果他们俩都参加会议&#xff0c;该小组的友好价值将会增加 1&#xff1b;如果其中只有一位参加会议&#xff0c;…

测试人员未来的3条出路

大家好&#xff0c;我是Z哥。前两天有个做测试的小伙伴加我微信问我测试相关的一些事情。她自己是从学习毕业就开始进入到互联网行业做测试的&#xff0c;到现在三年工作经验。她现在都不太敢跳槽&#xff0c;因为觉得自己没有什么核心竞争力&#xff0c;平常就是点点鼠标&…

[JavaWeb-MySQL]DQL_查询表中记录,语句

DQL&#xff1a;查询表中的记录 * select * from 表名;1. 语法&#xff1a;select字段列表from表名列表where条件列表group by分组字段having分组之后的条件order by排序limit分页限定2. 基础查询1. 多个字段的查询select 字段名1&#xff0c;字段名2... from 表名&#xff1b…

团体程序设计天梯赛-练习集L1-025 正整数A+B (15分)(getline输入)

题目&#xff1a; 题的目标很简单&#xff0c;就是求两个正整数A和B的和&#xff0c;其中A和B都在区间[1,1000]。稍微有点麻烦的是&#xff0c;输入并不保证是两个正整数。 输入格式&#xff1a; 输入在一行给出A和B&#xff0c;其间以空格分开。问题是A和B不一定是满足要求…

自定义值类型一定不要忘了重写Equals,否则性能和空间双双堪忧

一&#xff1a;背景1. 讲故事曾今在项目中发现有同事自定义结构体的时候&#xff0c;居然没有重写Equals方法&#xff0c;比如下面这段代码&#xff1a;static void Main(string[] args){var list Enumerable.Range(0, 1000).Select(m > new Point(m, m)).ToList();var ite…

[JavaWeb-MySQL]DDL_操作数据库,表

DDL:操作数据库、表 1. 操作数据库&#xff1a;CRUD1. C(Create):创建* 创建数据库&#xff1a;* create database 数据库名称;* 创建数据库&#xff0c;判断不存在&#xff0c;再创建&#xff1a;* create database if not exists 数据库名称;* 创建数据库&#xff0c;并指定…

Division CodeForces - 1445C(数论因子相关)

题意&#xff1a; 找一个最大的数X&#xff0c;使p%x0且x%q!0&#xff0c;题目保证至少有一个答案满足题意。 题目&#xff1a; Oleg’s favorite subjects are History and Math, and his favorite branch of mathematics is division. To improve his division skills, O…

使用 Windows Terminal 连接远程主机

使用 Windows Terminal 连接远程主机IntroWindows Terminal 是微软新推出来的一个全新的、流行的、功能强大的命令行终端工具。包含很多来社区呼声很高的特性&#xff0c;例如&#xff1a;多 Tab 支持、富文本、多语言支持、可配置、主题和样式&#xff0c;支持 emoji 和基于 G…

[JavaWeb-MySQL]DML_操作表

DML&#xff1a;增删改表中数据 1. 添加数据&#xff1a;* 语法&#xff1a;* insert into 表名(列名1,列名2,...列名n) values(值1,值2,...值n);* 注意&#xff1a;1. 列名和值要一一对应。2. 如果表名后&#xff0c;不定义列名&#xff0c;则默认给所有列添加值insert into …

.Net Core实现区块链初探

区块链这么火&#xff0c;咱也跟个风。一、前言最近&#xff0c;银行总行关于数字货币即将推出的消息频传&#xff0c;把BTC也带得来了一波反弹。借着这个风&#xff0c;我们也研究一下区块链。通常大家说到区块链&#xff0c;实际包括两部分概念&#xff1a;第一个概念&#x…

Divide and Sum CodeForces - 1445D(排列组合+逆元)

题意&#xff1a; 给定一个长度为2n的数组&#xff0c;将数组分成两个长度为n的数组p,q&#xff0c;将p从小到大排序&#xff0c;将q从大到小排序&#xff0c;对于每种分法&#xff0c;f(p,q)∑i1n\sum_{i1}^{n}∑i1n​|xi−yi|.求总和 题目&#xff1a; You are given an a…

[Java基础]自定义注解之属性定义

代码如下: package AnnoDemo01;public enum Person {p1,p2; }package AnnoDemo01;public interface MyAnno2 {}package AnnoDemo01;public interface MyAnno {int show1();String show2();Person per();MyAnno2 ann02();String[] strs(); }定义了属性&#xff0c;在使用时需要…

微软开源 Tye 项目,可简化微服务开发

微软近期开源了一款开发人员工具 Tye&#xff0c;能够用于简化微服务以及分布式应用程序的开发、测试以及部署过程。项目地址&#xff1a;https://github.com/dotnet/tye。该项目负责人 Amiee 表示&#xff0c;在构建由多个项目组成的应用程序时&#xff0c;开发者通常希望能够…