(step 8.2.10)hdu 1729(Stone Game——NIM游戏变形)
来源:互联网 发布:小众品牌知乎 编辑:程序博客网 时间:2024/05/01 09:24
题目大意:输入一个整数n,表示盒子数,在接下来的n行中,每行有两个整数s,c。分别表示盒子的容量和盒子中的石头数。。
游戏规则如下:
1)假如现在盒子里面有c个石头,那么游戏者能忘盒子里放1 ~ c*c 个石头。所放的石头不能超过盒子的容量
2)当某个游戏者不能放石头时(即盒子慢的时候),那么他就输了
解题思路:
给出一些盒子,盒子有容量限制,有初始容量,每次给某一个盒子中添加石头。
添加的数量必须小于等于盒子中已有数量的平方。
感觉上有一点像 巴什博弈,当然肯定比那个复杂
对于上限为S,当前容量如果为C,如果C+C*C<S&&(C+1)+(C+1)*(C+1)>=S,那么对于(S,C)显然是一个必败态
因为你不管一次取多少,不可能直接获胜,而对方都能直接获胜。
那么就继续递归求C状态。
如果最大的必败T>当前的C,那么就求出C后继中最小,也就是S-C
代码如下:
/* * 1729_1.cpp * * Created on: 2013年9月2日 * Author: Administrator */#include <iostream>#include <math.h>using namespace std;int getSG(int s , int c){int t = (int)sqrt((double)s );while(t + t*t >= s){t--;}if(c > t){return s - c;}else{return getSG(t,c);}}int main(){int n;int count = 1;while(scanf("%d",&n)!=EOF,n){int s ;int c;int i;int t = 0;for(i = 0 ; i < n ; ++i){scanf("%d%d",&s,&c);t ^= getSG(s,c);}if(t == 0){printf("Case %d:\nNo\n",count++);}else{printf("Case %d:\nYes\n",count++);}}}
- (step 8.2.10)hdu 1729(Stone Game——NIM游戏变形)
- (step 8.2.11)hdu 1730(Northcott Game——NIM游戏变形)
- 10165 - Stone Game(Nim游戏)
- HDU 5996 dingyeye loves stone(Nim 变形)
- HDU 1729 Stone Game(SG函数变形)
- poj 1740 A New Stone Game nim变形
- hdu 1729 Stone Game
- Hdu 1729 Stone Game
- HDU 1729 Stone Game
- HDU 1729 Stone Game
- hdu 1729 Stone Game
- hdu 1730 Northcott Game (nim博弈变形)
- Nim游戏 Nim Game
- HDU 1730 Northcott Game NIM游戏
- HDU 5011-game -nim游戏变种
- HDU 1730 Northcott Game(Nim博弈变形)
- Nim游戏变形之一
- Nim 游戏及其变形
- 吃金币小游戏笔记
- BMP文件格式
- 什么情况下使用Cron
- 九月
- ajax实现异步加载页面,实现信息实时更新
- (step 8.2.10)hdu 1729(Stone Game——NIM游戏变形)
- Opencv聚类函数 partition()
- hadoop集群负载不均衡及balance工具详解
- QTableWidget的用法总结
- ROBOT框架下启动IE的小问题与解决办法
- 3-5乘法表问题
- 微知识]模块的封装(一):C语言类的封装
- [WIP] Fedora 17上部署Ceph ( by quqi99 )
- C++中静态类型和动态类型