HDU 3537 Daizhenyang's Coin
来源:互联网 发布:酷炫爆炸js网站效果 编辑:程序博客网 时间:2024/05/29 05:56
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3537
题意:翻硬币游戏,如果一枚硬币正面朝上,你可以将它翻过来,并且自选0~2颗它左边的硬币,改变它们的状态(正反交替)。谁不能翻谁输。
思路:定义硬币全反时的sg为0,现在单个游戏就是只有一枚硬币朝上,其余都是反,其他情况都可以由单一游戏组合而成。如果位置i有一个正面朝上的硬币,其余都是反,那么这枚硬币翻过来的时候,它可以到达的局面是1、sg = 0 2、sg(j)j位置的硬币朝上,其余都是反(j<i) 3、出现两个正面朝上的硬币,变成组合游戏sg(j)和sg(k)。我们把sg函数打表出来就可以找到规律。
hihocoder上有这道题的简化版,讲的比较详细
http://hihocoder.com/problemset/problem/1172
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <cstdlib>#include <iostream>#include <algorithm>#include <stack>#include <map>#include <set>#include <vector>#include <sstream>#include <queue>#include <utility>using namespace std;#define rep(i,j,k) for (int i=j;i<=k;i++)#define Rrep(i,j,k) for (int i=j;i>=k;i--)#define Clean(x,y) memset(x,y,sizeof(x))#define LL long long#define ULL unsigned long long#define inf 0x7fffffff#define mod 100000007const int maxn = 1009;int sg[maxn];map<LL,int> flag;LL cal( LL x ){ int ans = 0; LL temp = x; while( temp ) { if ( temp & 1 ) ans++; temp >>= 1; } if ( ans & 1 ) return x * 2; return x*2+1;}void init(){ bool f[maxn]; sg[0] = 0; rep(i,1,100) { Clean(f,false); rep(j,0,i-1) f[ sg[j] ] = true; rep(j,0,i-1) rep( k,0,i-1 ) if ( j != k ) f[ sg[j] ^ sg[k] ] = true; rep(j,0,maxn-1) if ( !f[ j ] ) { sg[i] = j; break; } printf("%d : %d %I64d\n",i-1,sg[i] , cal(i-1)); }}int main(){ //init(); LL n,temp; LL ans; while( scanf("%I64d",&n) == 1 ) { flag.clear(); ans = 0; rep(i,1,n) { scanf("%I64d",&temp); if ( !flag[temp] ) ans ^= cal( temp ); flag[temp] = 1; } puts( ans==0 ? "Yes" : "No" ); } return 0;}
0 0
- HDU 3537 Daizhenyang's Coin
- 【hdu 3537】Daizhenyang's Coin
- HDOJ 3537 Daizhenyang's Coin
- hdu 3537 Daizhenyang's Coin(博弈-翻硬币游戏)
- HDU 3537 Daizhenyang's Coin (经典翻硬币博弈问题)
- HDU 3537 Daizhenyang's Coin 翻硬币博弈
- HDU 3537 Daizhenyang's Coin(博弈-sg)
- HDU 3537 Daizhenyang's Coin (Mock Turtles 游戏)
- HDU 3537 Daizhenyang's Coin (博弈论、翻硬币游戏)
- hdu3537 Daizhenyang's Coin
- hdu 3537 Daizhenyang's Coin 博弈(Nim游戏+sg定理+找规律)
- HDOJ 3537 Daizhenyang's Coin (翻硬币游戏)
- hdu3537 Daizhenyang's Coin 翻硬币,(Mock Turtles游戏)
- HDU3537-Daizhenyang's Coin(博弈SG-打表)
- HDU's ACM 2069 Coin Change
- hdu3446 daizhenyang's chess,一般图匹配
- hdu3446 daizhenyang's chess 【一般图匹配】
- Coin HDU
- Leetcode之路 371. Sum of Two Integers
- jira中issue状态的改变触发Jenkins构建
- 运维日记009 - 认识Linux上的桑巴舞——Samba
- LeetCode 33 Search in Rotated Sorted Array
- 进程间通信(IPC)以及同步
- HDU 3537 Daizhenyang's Coin
- Android Frequently Asked Questions for Open Source
- 使用secureCRT连接服务器,防超时断开
- iOS 本地化入门教程
- PCIe体系结构zz
- main函数的几种可行的写法
- 数据结构实验之栈五:下一较大值(一)
- 一个变种NTKO的实现方式
- 1883: 蛤玮当上主席(水)