博弈论简单题集合 poj1067&poj2234&poj2848&poj2975
来源:互联网 发布:淘宝旗帜 编辑:程序博客网 时间:2024/05/16 07:20
poj1067 威佐夫博弈模板题
既然是模板题蒟蒻在这里就不多加解释了,反正我也是背的公式……
#include<cstdio>#include<cmath>#include<algorithm>using namespace std;int main(){ int a,b; while(scanf("%d%d",&a,&b)!=EOF){ if(a>b) swap(a,b); int i=b-a; int aa=i*(sqrt(5.0)+1)/2;//sqrt要求参数为非负浮点数 if(a==aa) printf("0\n"); else printf("1\n"); } return 0;}
poj2234 NIM模板题
#include<cstdio>#include<cstring>using namespace std;int main(){ int n; while(scanf("%d",&n)!=EOF){ int sg=0,a; for(int i=1;i<=n;i++){ scanf("%d",&a); sg^=a; } if(!sg) printf("No\n"); else printf("Yes\n"); } return 0;}
poj2975 NIM游戏的变形
题意:
给定一种Nim状态(相当于含N堆石头),求能有几种方法能通过调整某一堆石头的状态(只准取出),使新的Nim状态为必败态。(或者说求出所给的Nim游戏状态有多少种方法能够赢)
解法:
这道题还是比较简单的。
我们知道NIM状态为必败态那么异或和=0
现在a1^a2^a3……^ai……^an=XOR
要使a1^a2^a3……^ai’……^an=0
易求出ai’的大小,并判断ai’是否小于ai,如果是,ans++(因为石子只允许取出)
#include<cstdio>using namespace std;const int N=1000+5;int xorr[N];int main(){ int n; while(scanf("%d",&n)&&n){ int ans=0,a; for(int i=1;i<=n;i++){ scanf("%d",&a); xorr[i]=xorr[i-1]^a; } for(int i=1;i<=n;i++){ int sh=xorr[i-1]^xorr[n]^xorr[i]^0; int used=xorr[i]^xorr[i-1]; //在异或的时候没有注意运算符的先后顺序 //位运算的优先级是最低的 if(sh<used) ans++; } printf("%d\n",ans); } return 0;}
poj2848
这道题好像没有用到sg函数之类的基础知识,主要还是考脑子想……
然而蒟蒻我的脑子好像比较小,所以看的题解……
题意:
题目的意思就是两个人轮流拿硬币,Alice先拿,Alice拿的时候可以选择拿走一个或者拿走相邻的两个,谁拿完最后的石子胜利。
解法:
易得 在1和2时先手必胜 3时先手必败
其余时候:
偶数时:当先手取1或2 那么后手就取对称位置的相同数量的棋子 为先手必败态
奇数时:先手取1后手取2 先手取2后手取1 此时是偶数 又是先手必败态
先手-> 后手->先手
p <-n <-p
#include<cstdio>using namespace std;int main(){ int n; while(scanf("%d",&n)&&n){ if(n==1||n==2) printf("Alice\n"); else printf("Bob\n"); } return 0;}
阅读全文
0 0
- 博弈论简单题集合 poj1067&poj2234&poj2848&poj2975
- 简单博弈论 POJ2484 POJ2975
- poj2234 Matches Game博弈论
- NIM游戏-博弈论(poj2975+CodeForces
- POJ1067 取石子游戏(博弈论)
- HDU1850博弈论_NIM游戏——POJ2975
- POJ2234
- poj2234
- poj2234
- poj2234
- poj2234
- poj2975
- POJ1067
- poj1067
- poj1067
- POJ1067
- poj1067
- poj1067
- 东方数智发布新品AIDOL™,打造人工智能偶像全息平台
- Google 顶级论文:机器学习系统,隐藏多少技术债?
- DP专题
- 理查德 · 塞勒获诺贝尔经济学奖!曾出演奥斯卡电影,他让经济学更人性
- 智能生态系统的产业架构与趋势研究
- 博弈论简单题集合 poj1067&poj2234&poj2848&poj2975
- 每日英语阅读(六十八)
- 经典排序算法总结
- HDU3635 Dragon Balls 解题报告【带权并查集】
- Java如何向外提供接口
- android开发之GPS定位详解
- 怎么认证微信服务号-微信公众号使用教程27
- AI大事件 | WaveNet推出了谷歌助手,苹果发布CoreML转换器
- 报名 | 2017英特尔软件开发者大会(成都、西安、广州)