landoj--1604--Play Apple(博弈)

来源:互联网 发布:苹果海马助手软件 编辑:程序博客网 时间:2024/05/18 00:56
1604 - Play Apple
Time Limit: 1000MS   Memory Limit: 65536KB   
Total Submit: 441  Accepted: 176  Special Judge: No
Description

There are N apples. Two people take turns to either: 
1. Divide the apple into two piles with different numbers.
2. The other people selects a pile of apples as the beginning of the next turn.
If someone can not meet the requirements, he is lost. Will the first one win the game if both use the best strategy?

Input
There are multiple test cases.
The first line of each case contains a integer N. ( 1 <= N <= 1000000000 )
Output
If the first person will win, output “Yes”. Otherwise, output “No”.
Sample Input
2
3
4
Sample Output
No
Yes
No
题意:现在有一堆苹果,这些苹果有n个,第一个人将苹果分为两份,这两份的数目应该是不一样的,第二个人选一堆分为不同的两份,循环下去,直到有一个人分不下去
思路:从小到大列举每一个数,看他们是必败点还是必胜点,然后就可以找到规律了,1,2为必败点,3是必胜点,大于3之后如果这个数减1之后还可以被3整除,那麽这个数就是必败点,否则就是必胜点
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){int n;while(scanf("%d",&n)!=EOF){if(n==3)printf("Yes\n");else if(n==1||n==2)printf("No\n");else if((n-1)%3==0)printf("No\n");else printf("Yes\n");}return 0;}


0 0