随笔(博弈)

虽然不懂SG函数,但是还是知道如何找规律的。嘻嘻嘻(*^__^*) 嘻嘻

题目描述:Stone Game

Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 8 Accepted Submission(s) : 4

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

There are three piles of stone(not empty), BCC and DDQ turn to proceed as follows: firstly choose a pile of stone to throw away, then in the remaining two piles of stone, choose one to divide into two piles of stone(not empty). The first to complete the operation is the winner. The game is first by BCC . BCC is so smart, DDQ wants to know if he can win, you can tell him?

Input

The first line is a positive integer T(<=500), denoting the number of cases followed. Each case consists of three positive integer A, B and C(1<=A,B,C<=2000000000), representing number of three piles of stone.

Output

For each case, if DDQ always win, output "YES", else output "NO" in one line.

Sample Input

5
1 1 1
2 2 2
5 6 7
4 2 2
12 28 4

Sample Output

YES
YES
NO
NO
YES
 
分析:首先找到必败点(1,1,1),(2,2,2),以此类推(2,1,1)为必胜点,(3,1,1)为必胜点,(3,2,1)(3,2,2)(3,3,2)为必胜点。(3,3,3)为必胜点。再继续推到(6,6,6)可以找到必败点有个规律:如果三个点为奇数那么先手必败,再看看偶数点(4,2,2)为必胜点(6,2,2)为必败点。继续举出全偶的例子可知。当(a%2,b%2,c%2)全为奇数时,先手必败。
 
代码:
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,t;
   scanf("%d",&t);
    while(t--)
    {
      scanf("%d%d%d",&a,&b,&c);
       while(a%2==0&&b%2==0&&c%2==0)
       {
           a=a/2;
           b=b/2;
           c=c/2;
       }  
      if(a%2==1&&b%2==1&&c%2==1)
           printf("YES%\n");
      else  printf("NO%\n");        
    }
    return 0;
}
      

你可能感兴趣的:(随笔(博弈))