Codeforces Round #399 E Game of Stones 博弈
来源:互联网 发布:数据魔方在哪里看 编辑:程序博客网 时间:2024/06/05 17:06
http://codeforces.com/contest/768/problem/E
题意:
给n堆石子,在一堆石头上取的石头数量只能去一次,比如你在一堆石子上取了了4个石子,那么接下里你就不能在这堆石子上取4个石子了.问后手是否必胜
做法:
╭(╯^╰)╮ 肯定是在NIM博弈基础上变了变,看了看题解。
NIM博弈就是异或和,最后看ans是否为0。对于这个题,考虑到nim中石子数量其实就是最多能取石子的步数,最后的亦或和也就是最大步数的亦或和,我们可以去求下这个游戏中每堆石子最多能取的步数,这样就能转换为普通的nim了.每堆石子最多能取的步数就好好求了,每堆石子我们按1,2,3,4..n的顺序去取石子,当剩下的石子小于等于n的时候,就不能再取了,所以n就是最大步数,然后我们去求下亦或和就可以。
/// .-~~~~~~~~~-._ _.-~~~~~~~~~-./// __.' ~. .~ `.__/// .'// \./ \\`./// .'// | \\`./// .'// .-~"""""""~~~~-._ | _,-~~~~"""""""~-. \\`./// .'//.-" `-. | .-' "-.\\`./// .'//______.============-.. \ | / ..-============.______\\`./// .'______________________________\|/______________________________`.#pragma comment(linker, "/STACK:1024000000,1024000000")#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>#include <bitset>using namespace std;#define pi acos(-1)#define s_1(x) scanf("%d",&x)#define s_2(x,y) scanf("%d%d",&x,&y)#define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z)#define s_4(x,y,z,X) scanf("%d%d%d%d",&x,&y,&z,&X)#define S_1(x) scan_d(x)#define S_2(x,y) scan_d(x),scan_d(y)#define S_3(x,y,z) scan_d(x),scan_d(y),scan_d(z)#define PI acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define fOR(n,x,i) for(int i=n;i>=x;i--)#define fOr(n,x,i) for(int i=n;i>x;i--)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");#define db double#define ll long long#define mp make_pair#define pb push_backtypedef long long LL;typedef pair <int, int> ii;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,1,-1,-1,1};const int dy[]={0,1,0,-1,-1,1,-1,1};const int maxn=1e3+10;const int maxx=1e6+10;const double EPS=1e-8;const double eps=1e-8;const int mod=1e9+7;template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}template <class T>inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}if(IsN) num=-num;return true;}void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}void print(LL a){ Out(a),puts("");}//freopen( "in.txt" , "r" , stdin );//freopen( "data.txt" , "w" , stdout );//cerr << "run time is " << clock() << endl;int n;int a[maxx];void solve(){W(cin>>n){LL ans=0;FOR(1,n,i){int x;s_1(x);for(int j=0;;j++){x-=j;if(x<=j){a[i]=j;break;}}}FOR(1,n,i) ans^=a[i];if(ans) puts("NO");else puts("YES");}}int main(){ //freopen( "1.txt" , "r" , stdin ); //freopen( "data.txt" , "w" , stdout ); int t=1; //init(); //s_1(t); for(int cas=1;cas<=t;cas++) { //printf("Case #%d: ",cas); solve(); }}
阅读全文
0 0
- Codeforces Round #399 E Game of Stones 博弈
- Codeforces Round #399:E. Game of Stones
- Codeforces 768E Game of Stones 博弈
- codeforces 399 E. Game of Stones 博弈 思维题
- codeforces 768 E Game of Stones(博弈)
- Codeforces 768E Game of Stones 博弈SG(打表)
- CodeForces 768E Game of Stones (Nim博弈)
- Codeforces 768E Game of Stones
- codeforces 786E Game of Stones
- 768E Game of Stones[Nim游戏][博弈]
- HDU 5973 Game of Taking Stones 博弈+高精度
- ZOJ 3964 Yet Another Game of Stones (博弈)
- Game of Taking Stones (大数 + 威佐夫博弈 java写的)
- HDU5973 Game of Taking Stones (大数博弈)
- ZOJ 3964 Yet Another Game of Stones (博弈)
- ZOj 3964Yet Another Game of Stones(nim博弈)
- Codeforces Round #228 (Div. 2) E Fox and Card Game(贪心博弈)
- 解题报告:Codeforces Round #432 (Div. 2) E.Arpa and a game with Mojtaba (博弈)
- maven中pom文件已经加载到jar包但是在程序发布时jar包却没有加入到lib下
- 设计模式概念
- eclipse中java和xml的自动补全功能的配置方法
- 数据结构实验之二叉树三:统计叶子数
- java算式运算符
- Codeforces Round #399 E Game of Stones 博弈
- Maven3.04暂时不支持Servlet3的无web.xml形式
- Android学之客户端服务端Socket简单通信
- JavaScript 获取对象中第一个属性
- pca人脸识别个人理解及步骤
- HDOJ 1302 The Snail
- java try catch 吃掉异常与跑出异常的区别,以及在项目中是否改抛出异常的理解
- SpringBoot整合MyBatis例子
- 小知识点积累