HDU 2509 Be the Winner
2016-08-11 17:44
357 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2509
题意:有n堆苹果,每次可以取走一堆中任意连续的(可以取一堆中间的苹果把连续的一堆分成不连续的两堆),取完最后一个苹果的人输。
思路:Anti-SG,胜者有两种情况。
1、组合游戏的SG函数!=0,有某单一游戏的SG>1。
2、组合游戏的SG函数SG==0,无某单一游戏的SG>1。
然后打表找单一游戏的sg值规律,发现sg(i) = i。
#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 100000007
const int maxn = 1009;
int T;
void init()
{
int sg[maxn];
bool temp[maxn];
Clean(sg,0);
rep(i,1,50)
{
Clean(temp,false);
rep(j,1,i)
temp[ sg[j] ] = true;
rep(j,1,i-2)
rep(k,1,i-j-1)
temp[ sg[k] ^ sg[i-j-k] ] = true;
int j = 0;
while( temp[j] ) j++;
sg[i]= j;
cout<<i<<" : "<<sg[i]<<endl;
}
}
int main()
{
//init();
int n;
while( cin>>n )
{
int temp;
int ans = 0;
bool f = false;
rep(i,1,n)
{
cin>>temp;
f |= temp != 1;
ans ^= temp;
}
puts( ( ( f && ans ) || ( !f && !ans ) ) ? "Yes" : "No" );
}
return 0;
}
题意:有n堆苹果,每次可以取走一堆中任意连续的(可以取一堆中间的苹果把连续的一堆分成不连续的两堆),取完最后一个苹果的人输。
思路:Anti-SG,胜者有两种情况。
1、组合游戏的SG函数!=0,有某单一游戏的SG>1。
2、组合游戏的SG函数SG==0,无某单一游戏的SG>1。
然后打表找单一游戏的sg值规律,发现sg(i) = i。
#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 100000007
const int maxn = 1009;
int T;
void init()
{
int sg[maxn];
bool temp[maxn];
Clean(sg,0);
rep(i,1,50)
{
Clean(temp,false);
rep(j,1,i)
temp[ sg[j] ] = true;
rep(j,1,i-2)
rep(k,1,i-j-1)
temp[ sg[k] ^ sg[i-j-k] ] = true;
int j = 0;
while( temp[j] ) j++;
sg[i]= j;
cout<<i<<" : "<<sg[i]<<endl;
}
}
int main()
{
//init();
int n;
while( cin>>n )
{
int temp;
int ans = 0;
bool f = false;
rep(i,1,n)
{
cin>>temp;
f |= temp != 1;
ans ^= temp;
}
puts( ( ( f && ans ) || ( !f && !ans ) ) ? "Yes" : "No" );
}
return 0;
}
相关文章推荐
- HDU 2509 Be the Winner
- HDU 2509 Be The Winner ( Nim 博弈 )
- HDU(2509) Be the Winner /HDU(1907) John (Nim 博弈)
- hdu 1907——John & hdu 2509——Be the Winner
- hdu 2509 Be the Winner(博弈)
- HDU 2509 Be the Winner(Anti-Nim)
- HDU-2509-Be the Winner,博弈题~~水过~~
- HDU 2509 Be the Winner
- HDU 2509 Be the Winner
- hdu 2509 Be the Winner(博弈Nim)
- HDU 2509 Be the Winner
- (step8.2.2)hdu 2509(Be the Winner——简单博弈)
- (step8.2.2)hdu 2509(Be the Winner——简单博弈)
- [博弈]HDU 2509 Be the Winner
- HDU 2509 Be the Winner && HDU 1907 John (Nim博弈变形)
- HDU 2509 Be the Winner
- hdu 2509 Be the Winner
- hdu 2509 Be the Winner(博弈Nim)
- HDU 2509 Be the Winner(尼姆模板与hdu 1907类似的题目)
- hdu 2509 - Be the Winner(简单博弈)