1982: [Spoj 2021]Moving Pebbles

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 130  Solved: 88
[Submit][Status][Discuss]

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

HINT

鸣谢lqp18_31..

Source

 题解:
在纸上画画就可以得出必败态为:n为偶数且可以分成n/2组两两相同的石子堆。
例如:
n=8 
石子为:1 1 6 6 8 8 8 8
博弈的题都不太好想,要从小到大一个一个去尝试。
但。。。
代码。。。
 #include<bits/stdc++.h>
using namespace std;
int a[];
int main()
{
int n,i;
while(scanf("%d",&n)!=EOF)
{
for(i=;i<=n;i++)scanf("%d",&a[i]);
sort(a+,a+n+);
if(n%==)
{
for(i=;i<=n;i+=)if(a[i]!=a[i+])break;
if(i>n){printf("second player\n");continue;}
}
printf("first player\n");
}
return ;
}

Bzoj 1982: [Spoj 2021]Moving Pebbles 博弈论的更多相关文章

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

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

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

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

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

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

  4. BZOJ1982 [Spoj 2021]Moving Pebbles 【博弈论】

    题目 Moving Pebbles Two players play the following game. At the beginning of the game they start with ...

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

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

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

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

  7. BZOJ 2226 [Spoj 5971] LCMSum 最大公约数之和 | 数论

    BZOJ 2226 [Spoj 5971] LCMSum 这道题和上一道题十分类似. \[\begin{align*} \sum_{i = 1}^{n}\operatorname{LCM}(i, n) ...

  8. 三种做法:BZOJ 2780: [Spoj]8093 Sevenk Love Oimaster

    目录 题意 思路 AC_Code1 AC_Code2 AC_Code3 参考 @(bzoj 2780: [Spoj]8093 Sevenk Love Oimaster) 题意 链接:here 有\(n ...

  9. [SPOJ2021] Moving Pebbles

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

随机推荐

  1. ASP.NET错误页

    当页面发生错误的时候,ASP.Net会将错误信息展示出来,这样一来不好看,二来会泄露网站的内部实现信息,给网站带来安全隐患,因此需要定制错误页,发生错误时显示开发人员定制的页面404页面放点广告也是好 ...

  2. jquery 之效果

    // jquery 之效果 .css()既可以获取值,如 .css('fontSize'), 又可以设置内置属性,既可用驼峰式,也可以用连字符版,如 .css('background-color', ...

  3. 面试题:m个长度为n的ordered array,求top k 个 数字

    package com.sinaWeibo.interview; import java.util.Comparator; import java.util.Iterator; import java ...

  4. Qt之json解析

    Jsoner::Jsoner(QObject *parent) : QObject(parent){    QJsonObject json;    json.insert("loginna ...

  5. C++库编译

    C++库编译 1. POCO编译 进入源文件目录,选择相应的VS版本进行编译(build_vs140).    设置系统环境变量: POCO_BASE 2. Boost编译 ####简单编译    在 ...

  6. MINA的session.close

    现象:客户端session.close之后,并没有提出,客户端程序一直hold在那里: 解决:调用了session.getService().dispose(false)方法后,客户端程序完成了退出 ...

  7. Html DOM 常用属性和方法

    Node对象的节点类型***************************************************接口 nodeType常量 nodeType值 备注Element Node ...

  8. Codeforces Round #197 (Div. 2) : D

    这题也是一个线段树的水题: 不过开始题目没看明白,害得我敲了一个好复杂的程序.蛋疼啊.... 最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去... 以后比赛的时候不喝啤酒了,再也 ...

  9. maven安装和环境变量配置

    maven安装和环境变量配置 myeclipse自带maven(Maven4MyEclipse)创建项目:新建Web Projects项目,在新建的页面上打上maven的勾.新建的项目里会多出个pom ...

  10. 设计模式之观察者(Observer)模式 代码详解

    import java.util.ArrayList; import java.util.List; /** * User: HYY * Date: 13-10-28 * Time: 下午1:34 * ...