随笔(博弈)

虽然不懂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;
}
      

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值