BZOJ1982 [Spoj 2021]Moving Pebbles 【博弈论】
题目
- 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 【博弈论】的更多相关文章
- Bzoj 1982: [Spoj 2021]Moving Pebbles 博弈论
1982: [Spoj 2021]Moving Pebbles Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 130 Solved: 88[Submi ...
- BZOJ 1982: [Spoj 2021]Moving Pebbles [博弈论 对称]
给你N堆Stone,两个人玩游戏. 每次任选一堆,首先拿掉至少一个石头,然后移动任意个石子到任意堆中. 谁不能移动了,谁就输了... 以前在poj做过已经忘记了... 构造对称,选最多的一堆往其他堆分 ...
- BZOJ 1982 [Spoj 2021]Moving Pebbles(博弈论)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1982 [题目大意] 两个人玩游戏. 每次任选一堆,首先拿掉至少一个石头, 然后移动任意 ...
- [BZOJ1982][POJ1740][Spoj 2021]Moving Pebbles|解题报告
这道题的题意BZ和POJ上的都不大清楚... 大概就是给出n堆石子,以及初始每堆石子的个数 两个玩家交替操作,每个操作可以任意在一堆中取任意多的石子 然后再从这堆里拿若干个石子放到某个当前还存在的堆里 ...
- bzoj 1982: [Spoj 2021]Moving Pebbles【博弈论】
必败状态是n为偶数并且数量相同的石子堆可以两两配对,因为这样后手可以模仿先手操作 其他状态一定可以由先手给后手一步拼出一个必败状态(用最大堆补) #include<iostream> #i ...
- BZOJ 1982 / Luogu SP2021: [Spoj 2021]Moving Pebbles (找平衡状态)
这道题在论文里看到过,直接放论文原文吧 在BZOJ上是单组数据,而且数据范围符合,直接int读入排序就行了.代码: #include <cstdio> #include <algor ...
- [SPOJ2021] Moving Pebbles
[SPOJ2021] Moving Pebbles 题目大意:给你\(N\)堆\(Stone\),两个人玩游戏. 每次任选一堆,首先拿掉至少一个石头,然后移动任意个石子到任意堆中. 谁不能移动了,谁就 ...
- 题解 [SDOI2009]E&D/染色游戏/Moving Pebbles
E&D 染色游戏 Moving Pebbles E&D 题目大意 给出 \(2n\) 堆石子,\(2i-1\) 和 \(2i\) 为一组.每次可以选择一组删掉其中一堆,然后从同一组另外 ...
- [bzoj1982]Moving Pebbles
首先发现当n堆石子可以两两配对时,后手必胜,因为后手可以模仿先手那么当n堆石子不能两两配对时,先手必胜,因为先手可以做到让其两两配对,然后即先手必胜 这个东西用map维护即可 1 #include&l ...
随机推荐
- thinkphp5 前台模板的引入css,js,images
一:在公共的静态文件夹中建立我们模块的名称用来放置css,js,images 二:在配置文件config中定义需要的路径 三:在视图页面引入
- 最简单的bootloader的编写
目标:写出bootloader的第一阶段代码和第二阶段代码,并测试. 最简单的bootloader的编写步骤: 1. 初始化硬件:关看门狗.设置时钟.设置SDRAM.初始化NAND FLASH2. 如 ...
- 常用 css html 样式
CSS基础必学列表 CSS width宽度 CSS height高度 CSS border边框 CSS background背景 CSS sprites背景拼合 CSS float浮动 CSS mar ...
- Vue简单使用,
一些零碎的知识点: 在js中变量的声明 有三种方式: let,var, const let: 对应的是一个块级作用域 { let a = 12 } console.log(a) 这是未声明的, var ...
- linux ln 建立软链接-- 基于dubbo-zookeeper服务的 服务jar 引用公共的 lib
对于ln命令网上有很多的教程,这里不再复述, 其基本目的是:多个文件夹公用一个文件夹的里的文件. 其基本命令格式: ln [option] source_file dist_file (source_ ...
- CSS3单选动画
本示例实现了两种单选按钮动画效果,一种是缩放,一种是旋转,以下是html布局以及css样式 html:这里使用了label标签的for属性,以此来绑定radio <div class=" ...
- js 邮箱和手机号码验证
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Python: 列表的两种遍历方法
方法一:以列表中元素的下标进行访问 def traverse1(list1): for i in range(len(list1)): print(list1[i], end=' ') print() ...
- Error: Error while compiling statement: FAILED: SemanticException Unable to determine if hdfs://hadoopNode2:8020/user/hive/warehouse/test is encrypted...
1.发现问题: 在hive客户端或者beeline查询hive表时候报错: 根据报错信息查看,是在集群namenode做了HA之后,产生的hdfs路径不对的问题: 2.解决问题,修改hive元数据my ...
- 添加用户-查看用户列表-禁止默认root登陆
程序小屌丝狒狒: (Q971751392) linux添加用户 adduser feifei passwd [用户名] 设置密码 可以查看所有用户的列表 cat /etc/passwd w 可以查看 ...