poj 1704 Nim取子变形(一路向左)
来源:互联网 发布:欧冠足球2 球员数据 编辑:程序博客网 时间:2024/06/08 17:19
题意:一维格子上有若干棋子,每个格子中最多只能放置一枚棋子。一次行动为向左移动一颗棋子,移动的步数随意,但是棋子不能越过它左边的棋子。两人博弈,每人一动,最后不能移动者为负。
思路:将棋子视为两两一对。如果有奇数个棋子,就不考虑最前面的一个。 在每对棋子中,如果对方移动前一个,我方对后一个移动相同的步数,使得对与对之间的距离可以不作考虑。只需考虑每对棋子之间的距离,这即归结为Nim取子游戏:将每对棋子之间的距离视作一堆石子的个数,使得移动每对棋子的后一个,相当于减少了某堆石子的数量。
#include <stdio.h>#include <stdlib.h>int cmp(const int *a,const int* b){return (*a)-(*b);}int n,T;int s[1005];int main(){freopen("a.txt","r",stdin);scanf("%d",&T);while(T--){int i,res=0;scanf("%d",&n);for(i = 0;i<n;i++)scanf("%d",&s[i]);qsort(s,n,sizeof(int),cmp);if(n&1){res = s[0]-1;for(i = 2;i<n;i+=2)res ^= s[i]-s[i-1]-1;}elsefor(i = 1;i<n;i+=2)res ^= s[i]-s[i-1]-1;if(res)printf("Georgia will win\n");elseprintf("Bob will win\n");}return 0;}
0 0
- poj 1704 Nim取子变形(一路向左)
- poj-1704 nim变形
- poj 2234 博弈论Nim取子游戏
- POJ 1704 Georgia and Bob (Nim游戏变形)
- POJ 1704 Georgia and Bob (博弈 Nim游戏变形)
- POJ 1704 Georgia and Bob <Nim变形>
- Nim取子游戏 (SG函数)
- Nim取子游戏
- Nim取子游戏
- Nim(Nim博弈变形)
- POJ 2975 Nim(尼姆博弈的变形)
- poj 3537 Crosses and Crosses(NIM变形)@
- POJ 3480 John Anti-Nim博弈变形
- poj 2960 S-Nim Nim博弈变形 有限取法
- poj1704(变形Nim博弈)
- poj 1704 (nim博弈)
- Poj 1067 取石子游戏(NIM,威佐夫博奕)
- nim取子游戏 阶梯博弈
- php抽象类
- hdu 1049 Climbing Worm
- POJ 1789 Truck History
- SQLite创建数据库失败
- CALL指令有多少种写法
- poj 1704 Nim取子变形(一路向左)
- HDU1166-敌兵布阵
- 周世黑鸭带您走向成功之路
- hdu3440 House Man
- HDU 1180 诡异的楼梯 (DFS)
- ASP.net 学习路线(详细)
- ADO.NET之9-非连接模式,内存中的数据库DataSet,DataTable---ShinePans
- Science上发表的超赞聚类算法
- c/c++中的浮点数的表示方法