HDU3537-Daizhenyang's Coin(博弈SG-打表)

简介:

<span style="color: green; font-family: Arial; font-size: 12px; background-color: rgb(255, 255, 255);">Daizhenyang's Coin
</span>
<span style="color: green; font-family: Arial; font-size: 12px; background-color: rgb(255, 255, 255);">Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)</span>
Total Submission(s): 320    Accepted Submission(s): 146


Problem Description
We know that Daizhenyang is chasing a girlfriend. As we all know, whenever you chase a beautiful girl, there'll always be an opponent, or a rival. In order to take one step ahead in this chasing process, Daizhenyang decided to prove to the girl that he's better and more intelligent than any other chaser. So he arranged a simple game: Coin Flip Game. He invited the girl to be the judge.
In this game, n coins are set in a row, where n is smaller than 10^8. They took turns to flip coins, to flip one coin from head-up to tail-up or the other way around. Each turn, one can choose 1, 2 or 3 coins to flip, but the rightmost selected must be head-up before flipping operation. If one cannot make such a flip, he lost.
As we all know, Daizhenyang is a very smart guy (He's famous for his 26 problems and Graph Theory Unified Theory-Network Flow does it all ). So he will always choose the optimal strategy to win the game. And it's a very very bad news for all the competitors.
But the girl did not want to see that happen so easily, because she's not sure about her feelings towards him. So she wants to make Daizhenyang lose this game. She knows Daizhenyang will be the first to play the game. Your task is to help her determine whether her arrangement is a losable situation for Daizhenyang.
For simplicity, you are only told the position of head-up coins. And due to the girl's complicated emotions, the same coin may be described twice or more times. The other coins are tail-up, of course.
Coins are numbered from left to right, beginning with 0.
 

Input
Multiple test cases, for each test case, the first line contains only one integer n (0<=n<=100), representing the number of head-up coins. The second line has n integers a1, a2 … an (0<=ak<10^8) indicating the An-th coin is head up.
 

Output
Output a line for each test case, if it's a losable situation for Daizhenyang can, print "Yes", otherwise output "No" instead.
 

Sample Input
 
 
0 1 0 4 0 1 2 3
 

Sample Output
 
 
Yes No Yes
翻硬币的经典例子-MOCK-TURTLES
打表发现:
x: 0 1 2 3 4 5 6 7...
g(x): 1 2 4 7 8 11 13 14...
发现x化作2进制1的个数为奇数时。g(x)= 2*x 否则 g(x) = 2*x+1 SG和即是答案。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
int n;
set<int>st;
int main(){

    while(~scanf("%d",&n)){
        int ans = 0;
        st.clear();
        for(int i = 0; i < n; i++){
            int t;
            scanf("%d",&t);
            if(st.count(t)==0){
                if(t==0) ans ^= 1;
                else{
                    int k = t,cnt = 0;
                    while(k){
                        k = k&(k-1);
                        cnt++;
                    }
                    if(cnt%2==0) ans ^= (2*t+1);
                    else ans ^= 2*t;

                }
                st.insert(t);
            }

        }
        if(ans==0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}






本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5077760.html,如需转载请自行联系原作者

相关文章
|
8月前
华为机试HJ107:求解立方根
华为机试HJ107:求解立方根
109 1
|
7月前
hdu 1052 Tian Ji -- The Horse Racing【田忌赛马】(贪心)
hdu 1052 Tian Ji -- The Horse Racing【田忌赛马】(贪心)
33 0
PTA 7-4 最近的斐波那契数 (20 分)
斐波那契数列 F n ​ 的定义为:对 n≥0 有 F n+2 ​ =F n+1 ​ +F n ​ ,初始值为 F 0 ​ =0 和 F 1 ​ =1。
79 0
PTA 1056 组合数的和 (15 分)
给定 N 个非 0 的个位数字,用其中任意 2 个数字都可以组合成 1 个 2 位的数字。要求所有可能组合出来的 2 位数字的和。
96 0
|
机器学习/深度学习
HDU2376——Average distance(思维+树形DP)
HDU2376——Average distance(思维+树形DP)
76 0
[UVA1364 | POJ | NC]Knights of the Round Table | Tarjan 求点双 | 二分图 | 综合图论
我们可以很轻松地发现,被提出的都是在点双连通分量之外的,比如该图中的1 和 5 ,那么怎么判断哪些点不在环中呢? 此时我们还可以逆向思考,不 在 环 中 的 = = 总 的 − 在 环 中 的,所以说现在问题就转换成了满足条件的环内的点的个数
106 0
[UVA1364 | POJ | NC]Knights of the Round Table | Tarjan 求点双 | 二分图 | 综合图论
|
Java
HDU 2147 kiki&#39;s game(规律,博弈)
kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others)Total Submission(s): 10763    Accepted Submission(s): ...
880 0
LeetCode 70 Climbing Stairs(爬楼梯)(动态规划)(*)
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/50514606 翻译 你正在爬一个楼梯。
919 0