Codeforces Round #366 (Div. 2) B. Spider Man (组合游戏)
来源:互联网 发布:网络女作家 编辑:程序博客网 时间:2024/04/29 13:19
题目链接
有一个2个人玩的游戏,有n个圆环,每次的操作是选择一个大小不小于2的圆环,把它分成x,N-x(1<=x < N)2个子圆环。
换句话说,就是给你n堆石子,然后每次选择大小不小于2的分成2个小堆,且每堆大小大于0,不能操作的输。
题目问的是,给出n堆,n个询问,选择前i堆作为游戏开始,先手赢还是后手赢。
先用sg函数,打表计算下规律,打表的规律是奇数是0,偶数是1
然后直接异或就好了
#include<bits/stdc++.h>using namespace std;#define cl(a,b) memset(a,b,sizeof(a))#define LL long long#define pb push_back#define gcd __gcd#define For(i,j,k) for(int i=(j);i<k;i++)#define lowbit(i) (i&(-i))#define _(x) printf("%d\n",x)const int maxn = 1e6+10;const int inf = 1 << 28;set<int> s;int sg[maxn];int grundy(int k){ s.clear(); sg[1]=0; // s.insert(sg[1]); for(int i=1;i<k;i++){ s.insert(sg[i]^(sg[k-i])); } int ans = 0; while(s.count(ans))ans++; sg[k]=ans; return ans;}int sg_(int x){ if(x%2==0)return 1; else return 0;}int main(){ /* for(int i=1;i<=25;i++){ printf("%2d ",i); } cout<<endl; for(int i=1;i<=25;i++){ printf("%2d ",grundy(i)); } cout<<endl;*/ int n;scanf("%d",&n); LL ans = 0; for(int i=0;i<n;i++){ LL x;scanf("%lld",&x); ans^=sg_(x); // cout<<"ans = "<<ans<<endl; printf("%s\n",ans?"1":"2"); } return 0;}
0 0
- Codeforces Round #366 (Div. 2) B. Spider Man (组合游戏)
- Codeforces Round #366 (Div. 2) B. Spider Man (Nim游戏)
- 【Codeforces Round #366 (Div. 2)】Codeforces 705B Spider Man
- Codeforces #366(Div.2)B.Spider Man【水题】
- CodeForces 705B Spider Man(蜘蛛侠游戏)
- Codeforces Round #366 (Div. 1) B. Ant Man (贪心)
- CodeForces 705B Spider Man 思维游戏题
- Codeforces-705B-Spider Man
- CodeForces 705B Spider Man
- Codeforces 705B.Spider Man
- 贪心+链——Ant Man(Codeforces Round #366 (Div. 1) B )
- (组合)Codeforces AIM Tech Round 4 (Div. 2) B. Rectangles
- Coderforces #366 B Spider Man
- codeforces 705 B. Spider Man (思维)
- 【模拟】Codeforces 705B Spider Man
- Codeforces Round #366 (Div. 2) [D] Ant Man
- Codeforces Round #366 (Div. 1):Ant Man(贪心)
- Codeforces Round #366 (Div. 1):Ant Man(贪心)★
- HDU 5804 Price List
- [DP]Bridge设计模式
- docker-compose的安装和设定
- Codeforces Round #366 (Div. 2) A. Hulk (简单模拟)
- 领导说我对任务的理解是错的
- Codeforces Round #366 (Div. 2) B. Spider Man (组合游戏)
- 夏令营day4总结
- 《技术人创业攻略》-用技术改变世界!
- PAT乙级:1006. 换个格式输出整数 (Java)
- Codeforces Round #366 (Div. 2) C. Thor(模拟)
- 在PyCharm中运行django 项目
- JAVAIO一次写入任意字符固定套路
- 登录安全性 一天内连续输入密码错误3次,第二天才能登录(过了当天凌晨24点),实现原理
- 欧拉函数PHI