题目

  1. 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,两个人玩游戏. 每次任选一堆,首先拿掉至少一个石头,然后移动任意个石子到任意堆中. 谁不能移动了,谁就输了…

输入格式

Each line of input has integers 0 < n <= 100000, followed by n positive integers denoting the initial piles.

输出格式

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.

输入样例

3 2 1 3

输出样例

first player

题解

博弈论的题目总是很神(shao)奇(nao)。。。。

但想清楚总是很简单

①根据博弈的套路,当石子堆两两配对,后手猥琐模仿先手,先手必败

②根据本题特点,石子可以拿取后自由移动;

1、若为奇数,一定不是两两配对,那么先手就可以取掉一点并移动使得堆数-1且两两配对

2、若为偶数,且不两两配对,那么先手可以通过一定操作使得两两配对

综上:只要一开始不是两两配对,先手必胜,否则必败

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u]; k != -1; k = ed[k].nxt)
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 1000000000;
inline int RD(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57) {out = (out << 1) + (out << 3) + c - '0'; c = getchar();}
return out * flag;
}
int A[maxn],n;
int main(){
n = RD();
if (n & 1) {puts("first player"); return 0;}
REP(i,n){
A[i] = RD();
if (i % 2 == 0 && A[i] != A[i - 1]) {puts("first player"); return 0;}
}
puts("second player");
return 0;
}

BZOJ1982 [Spoj 2021]Moving Pebbles 【博弈论】的更多相关文章

  1. Bzoj 1982: [Spoj 2021]Moving Pebbles 博弈论

    1982: [Spoj 2021]Moving Pebbles Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 130  Solved: 88[Submi ...

  2. BZOJ 1982: [Spoj 2021]Moving Pebbles [博弈论 对称]

    给你N堆Stone,两个人玩游戏. 每次任选一堆,首先拿掉至少一个石头,然后移动任意个石子到任意堆中. 谁不能移动了,谁就输了... 以前在poj做过已经忘记了... 构造对称,选最多的一堆往其他堆分 ...

  3. BZOJ 1982 [Spoj 2021]Moving Pebbles(博弈论)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1982 [题目大意] 两个人玩游戏. 每次任选一堆,首先拿掉至少一个石头, 然后移动任意 ...

  4. [BZOJ1982][POJ1740][Spoj 2021]Moving Pebbles|解题报告

    这道题的题意BZ和POJ上的都不大清楚... 大概就是给出n堆石子,以及初始每堆石子的个数 两个玩家交替操作,每个操作可以任意在一堆中取任意多的石子 然后再从这堆里拿若干个石子放到某个当前还存在的堆里 ...

  5. bzoj 1982: [Spoj 2021]Moving Pebbles【博弈论】

    必败状态是n为偶数并且数量相同的石子堆可以两两配对,因为这样后手可以模仿先手操作 其他状态一定可以由先手给后手一步拼出一个必败状态(用最大堆补) #include<iostream> #i ...

  6. BZOJ 1982 / Luogu SP2021: [Spoj 2021]Moving Pebbles (找平衡状态)

    这道题在论文里看到过,直接放论文原文吧 在BZOJ上是单组数据,而且数据范围符合,直接int读入排序就行了.代码: #include <cstdio> #include <algor ...

  7. [SPOJ2021] Moving Pebbles

    [SPOJ2021] Moving Pebbles 题目大意:给你\(N\)堆\(Stone\),两个人玩游戏. 每次任选一堆,首先拿掉至少一个石头,然后移动任意个石子到任意堆中. 谁不能移动了,谁就 ...

  8. 题解 [SDOI2009]E&D/染色游戏/Moving Pebbles

    E&D 染色游戏 Moving Pebbles E&D 题目大意 给出 \(2n\) 堆石子,\(2i-1\) 和 \(2i\) 为一组.每次可以选择一组删掉其中一堆,然后从同一组另外 ...

  9. [bzoj1982]Moving Pebbles

    首先发现当n堆石子可以两两配对时,后手必胜,因为后手可以模仿先手那么当n堆石子不能两两配对时,先手必胜,因为先手可以做到让其两两配对,然后即先手必胜 这个东西用map维护即可 1 #include&l ...

随机推荐

  1. MongoDB在单机上搭建分片副本集群(windows)

    ------------------------------1.安装MongoDB...... ------------------------------2.准备好文件夹 --config:配置文件 ...

  2. py3.7.1下pyinstaller 的安装及打包 坑

    实在无语了,写了个小程序,用pyinstaller打包,运行就出现这个pip install pywin32-ctypes.明明全部都已经安装了啊. 解决办法: 不要在工程设置里安装pyinstall ...

  3. is和==,编码补充

    一,is和==的区别: 1, 通过一个ID()可以查看到一个变量表示的值在内存中的地址.    s = 'alex' print(id(s)) # 4326667072 s = "alex& ...

  4. 网站安全检测 漏洞检测 对thinkphp通杀漏洞利用与修复建议

    thinkphp在国内来说,很多站长以及平台都在使用这套开源的系统来建站,为什么会这么深受大家的喜欢,第一开源,便捷,高效,生成静态化html,第二框架性的易于开发php架构,很多第三方的插件以及第三 ...

  5. 静态栈抽象数据类型stack实现

    #include<stdio.h> #include<stdbool.h> #include<stdlib.h> #define MAX_STACK_SIZE 10 ...

  6. 线程基础三 使用C#中的lock关键词

    C#中lock关键字主要是为确保当一个线程使用某些资源时,同时无法其他线程无法使用该资源.下面我们看看下面的小例子. static void Main(string[] args) { var c = ...

  7. 也谈js传值和传址

    通常的认识就是基本的数值元素是传值,对象等复杂结构传址,无需争论,一试便知. 首先是数值 var a = 1 var b = a a = 2 console.log(a) console.log(b) ...

  8. laravel读excel

    fileName = "test.xls";$filePath = "../storage/app/";Excel::load($filePath.$fileN ...

  9. Spring+Hiberate 多数据源的网文整理

    解决方案: http://www.th7.cn/Program/java/2011/10/23/44664.shtml 分析共享Spring配置数据源四种方式(附相应jar包)  :http://ww ...

  10. 关于 SSH Server 的整体设定

    # . 关于 SSH Server 的整体设定,包含使用的 port 啦,以及使用的密码演算方式 Port # SSH 预设使用 这个 port,您也可以使用多的 port ! # 亦即重复使用 po ...