【bzoj1982】【Spoj2021】【Moving Pebbles】【博弈论】
来源:互联网 发布:跨境电子商城源码 编辑:程序博客网 时间:2024/05/16 19:08
Description
2021. Moving Pebbles Two players play the following game. At the beginning of the game they start with n (1<=n<=100000) piles of stones. At each step of the game, the player chooses a pile and remove at least one stone from this pile and move zero or more stones from this pile to any other pile that still has stones. A player loses if he has no more possible moves. Given the initial piles, determine who wins: the first player, or the second player, if both play perfectly. 给你N堆Stone,两个人玩游戏. 每次任选一堆,首先拿掉至少一个石头,然后移动任意个石子到任意堆中. 谁不能移动了,谁就输了...
Input
Each line of input has integers 0 < n <= 100000, followed by n positive integers denoting the initial piles.
Output
For each line of input, output "first player" if first player can force a win, or "second player", if the second player can force a win.
Sample Input
3 2 1 3
Sample Output
first player
题解:博弈论的题都好神奇。
考虑如果这些石子能够两两配对配成n/2组(n为偶数),则是先手必败的。
因为这种情况下无论先手如何操作,后手都可以让局面回到等价的状态。
其余情况下先手必胜,因为其余情况下先手都有办法将局面变成先手必败。
代码:
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int n,a[100010];int main(){ cin>>n; if (n&1){cout<<"first player"<<endl;return 0;} for (int i=1;i<=n;i++)cin>>a[i]; sort(a+1,a+n+1); for (int i=1;i<=n;i+=2) if (a[i]!=a[i+1]){ cout<<"first player"<<endl; return 0; } cout<<"second player"<<endl;}
0 0
- 【bzoj1982】【Spoj2021】【Moving Pebbles】【博弈论】
- BZOJ1982 [Spoj 2021]Moving Pebbles 【博弈论】
- [BZOJ1982][Spoj 2021]Moving Pebbles(博弈)
- bzoj 1982 Moving Pebbles 博弈论
- BZOJ 1982 Spoj 2021 Moving Pebbles 博弈论
- bzoj 1982: [Spoj 2021]Moving Pebbles 博弈论
- 【bzoj 1982】Moving Pebbles(博弈论)
- BZOJ [Spoj 2021]Moving Pebbles(隐藏题)
- bzoj 1982: [Spoj 2021]Moving Pebbles (博弈)
- Pebbles
- MOVING
- 博弈论
- 博弈论
- 博弈论
- 博弈论
- 博弈论
- 博弈论
- 博弈论
- 操练Ubuntu14.10
- popToRootViewController
- 【HDU1863】畅通工程 (kruskal/并查集find)
- struts2文件上传 下载
- PAT 乙级 真题 1002. 写出这个数
- 【bzoj1982】【Spoj2021】【Moving Pebbles】【博弈论】
- 经典排序算法(2) -插入排序 InsertSort
- c++中的前向声明
- HDOJ 1016 Prime Ring Problem素数环【深搜】
- HDU 1452 Happy 2004
- 获取栈中最小值函数,时间复杂度为O(1)
- 详解 CSS 属性 - :before && :after
- SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax
- 通过execve在两个进程间传递环境变量