POJ 1740 A New Stone Game(博弈)
来源:互联网 发布:淘宝保健品规则 编辑:程序博客网 时间:2024/05/16 09:35
POJ 1740 A New Stone Game
题意:
每次对某堆拿走x个石头并向非空石堆转移yi个石头
x>0,yi>=0
yi的含义是说可以向多个石堆转移石头
直到无法操作者败
分析:
1.石堆的石头数成对相等的状态为败态(例如 1 1 2 2...)
2.所有不是上述情况的状态转移到全部成对相等花费的步数是1步,故为胜态
对于1:
完全的对称使得先手操作之后后手可以完全模仿先手的操作
对于2:
首先将已经相等的石堆对排除,假设有n堆石头全不相等,
将石堆按石头数从小到大排列之后:
x1,x2,x3,...,xn满足x[i] < x[i+1]
极限的情况是对任意的i x[i+1]-x[i] == 1
这样,x[n]比x[1]多(n-1),
而任意相邻的石堆相差1,要使x2到x[n-1]的石堆两两相等需要花费的石头数是(n-2)/2
而要做到x1和xn相等,只需拿走(n-2)/2+1个石头,并花费(n-2)/2个石头使其他的两两相等
而非极限情况,当x[i+1] - x[i] > 1
x[n]比x[1]多的石头数也就更多,依然有足够的石头做到使x[1] == x[n]且其他相邻两堆相等
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<vector>#include<algorithm>#define mem(a,x) memset(a,x,sizeof(a))using namespace std;typedef long long ll;const int inf = 0x3f3f3f3f;/*每次对某堆拿走x个石头并向非空石堆转移yi个石头x>0,yi>=0yi的含义是说可以向多个石堆转移石头 直到无法操作者败*/int a[111]; int main(){int n;while (cin>>n){if (!n) break;mem(a,0);for (int i = 0,x;i < n;++i){cin>>x;a[x]++;}bool win = false;for (int i = 0;i <= 100;++i){if (a[i]&1){//odd win = true;break;}}cout<<win<<endl;}return 0;}
java:
//package acm.poj1740;import java.util.*;//博弈public class Main {static int a[] = new int [111];public static void main(String[] args) {// TODO Auto-generated method stub@SuppressWarnings("resource")Scanner in = new Scanner (System.in);while (in.hasNext()){int n = in.nextInt();if (n == 0) break;Arrays.fill(a, 0);for (int i = 0,x;i < n;++i){x = in.nextInt();a[x]++;}boolean win = false;for (int i = 0;i <= 100;++i){if ((a[i]&1)!=0){win = true;break;}}if (win) System.out.println(1);else System.out.println(0);}}}
0 0
- poj 1740 A New Stone Game( 博弈)
- poj 1740 A New Stone Game(博弈)
- poj 1740 A New Stone Game(博弈)
- poj 1740 A New Stone Game 博弈
- POJ 1740 A New Stone Game【博弈】
- POJ 1740 A New Stone Game(博弈)
- 博弈 POJ A New Stone Game
- POJ 1740 A New Stone Game (博弈)
- poj 1740 A New Stone Game(博弈)
- POJ 题目1740 A New Stone Game(博弈)
- POJ 1740 A New Stone Game 博弈,规律
- [POJ](1740)A New Stone Game --找规律博弈(博弈)
- POJ 1740 A New Stone Game
- POJ 1740 A New Stone Game
- POJ 1740 A New Stone Game
- poj 1740 A New Stone Game
- poj-1740 A New Stone Game 博弈论
- POJ 1740 A New Stone Game(博弈论)
- Sublime Text 3使用
- 转一份在 51testing 上的讨论——如何测试一个门户网站是否可以支持10万用户同时在线?
- 网络安全那些事儿
- DES算法初探
- [spark] mllib决策树通过Strategy修改内存,java实现
- POJ 1740 A New Stone Game(博弈)
- C++学习笔记1 类与析构函数
- 【Linux开发】Ubuntu图形界面切换与磁盘扩展分区
- java定时任务
- VC 线程
- 我的Map实现
- JAVA MAP相关
- 启动MongoDB时cmd窗口一闪而过
- Java 程序员必须收藏的资源大全