AtCoder - 1999 Candy Piles
There are N piles of candies on the table. The piles are numbered 1 through N. At first, pile i contains ai candies.
Snuke and Ciel are playing a game. They take alternating turns. Snuke goes first. In each turn, the current player must perform one of the following two operations:
- Choose a pile with the largest number of candies remaining, then eat all candies of that pile.
- From each pile with one or more candies remaining, eat one candy.
The player who eats the last candy on the table, loses the game. Determine which player will win if both players play the game optimally.
Constraints
- 1≤N≤105
- 1≤ai≤109
Input
The input is given from Standard Input in the following format:
N
a1 a2 … aN
Output
If Snuke will win, print First
. If Ciel will win, print Second
.
Sample Input 1
2
1 3
Sample Output 1
First
At the beginning of the game, pile 2 contains the most candies. If Snuke eats all candies of this pile, Ciel has no choice but to eat the last candy.
Sample Input 2
3
1 2 1
Sample Output 2
First
If Snuke eats one candy from each pile, Ciel is again left with the last candy.
Sample Input 3
3
1 2 3
Sample Output 3
Second (假设高度有序,从左到右递减)
可以把问题转化成,初始在(0,0),有n个矩形拼成的凸多边形,第i个矩形是的左下角是(i-1,0),右上角是(i,h[i])。那么游戏就相当于每次只能向右或者向上走,不能走出多边形,问先手是否必胜。
可以先画一画1*1的小正方形的情况,可以发现不论右上角是什么状态,左下角一定和它的状态一样 (右上角必败比较好发现,必胜的话要多画几个其他点的状态)。
于是就可以直接暴力做了2333
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100005; int a[N],n;
bool sg; inline void solve(){
for(int i=1;i<=n;i++) if(i+1>a[i+1]){
for(int j=i+1;a[j]==i;j++) sg^=1;
sg|=(a[i]-i)&1,puts(sg?"First":"Second");
break;
}
} int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",a+i);
sort(a+1,a+n+1),reverse(a+1,a+n+1); solve(); return 0;
}
AtCoder - 1999 Candy Piles的更多相关文章
- AtCoder AGC002E Candy Piles (博弈论)
神仙题..表示自己智商不够想不到... 好几次读成最后拿的赢了,导致一直没看懂题解... 题目链接: https://atcoder.jp/contests/agc002/tasks/agc002_e ...
- @atcoder - AGC002E@ Candy Piles
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定 N 堆糖果,第 i 堆包含 ai 个糖果. 现在两人进行博 ...
- [Agc002E]Candy Piles
[Agc002E]Candy Piles 题目大意 有\(n\)个数,两人轮流操作,可以做以下操作之一: 删掉一个最大的数 将所有数-1 最后取没的人输,问先手是否必胜? 试题分析 直接决策不知道选哪 ...
- [AT1999] [agc002_e] Candy Piles
题目链接 AtCoder:https://agc002.contest.atcoder.jp/tasks/agc002_e 洛谷:https://www.luogu.org/problemnew/sh ...
- agc002E - Candy Piles(博弈论)
题意 题目链接 Sol Orz SovitPower #include<bits/stdc++.h> #define Pair pair<int, double> #defin ...
- 【AGC002E】Candy Piles 博弈论
题目大意 有\(n\)堆糖果,第\(i\)堆有\(a_i\)个. 两个人轮流决策,决策分为两种: 1.选择糖果数最多的一堆糖果,并把这堆糖全吃了. 2.在每堆非空的糖果堆里拿一颗糖吃掉. 吃掉最后一颗 ...
- AGC 002E.Candy Piles(博弈论)
题目链接 \(Description\) 给定\(n\)堆糖,数量分别为\(a_i\).Alice和Bob轮流操作.每次可以吃掉最多的一堆,也可以每堆各吃掉一个.无法操作的人输,求谁能赢. \(n\l ...
- [AtCoder AGC27A]Candy Distribution Again
题目大意:把$x$个糖果分给$n$个人,必须分完,如果第$i$个人拿到$a_i$个糖果,就会开心,输出最多多少人开心 题解:从小到大排序,判断是否可以让他开心,注意最后判断是否要少一个人(没分完) 卡 ...
- [atcoder002E] Candy Piles [博弈论]
题面: 传送门 思路: 每一堆糖排成一列,所有列横着放,形成一个阶梯型 两个决策相当于左边一列去掉和最下面一行去掉 那么这个模型可以转化为同样形状的网格图,向左上方走,走到边界的赢· 然后一波数学推导 ...
随机推荐
- python初步学习-python控制流
语句书写规范 缩进在python语言书写中非常重要,如果缩进不规范,执行程序将会报错 引用维基百科中的叙述: Python開發者有意讓違反了縮排規則的程序不能通過編譯,以此來強迫程序員養成良好的編程習 ...
- .net JsonHelper json帮助类
using Newtonsoft.Json; using System.Runtime.Serialization.Json; using System.Text; public class Json ...
- bing查询旁站脚本
#!/usr/bin/env python # -*- coding: UTF-8 -*- #by i3ekr import re,optparse,sys,requests,time,os pars ...
- Django【设计】settings方案
配置文件: 目标:配置文件,默认配置和手动配置分开,参考django的配置文件方案,默认配置文件放在内部,只让用户做常用配置 /bin/settings.py(手动配置) PLUGIN_ITE ...
- Opencv模块功能介绍
本文为原创作品,转载请注明出处 欢迎关注我的博客:http://blog.csdn.net/hit2015spring和http://www.cnblogs.com/xujianqing/ 站在巨 ...
- SUSE 11.3 linux ISO下载地址
http://linux.iingen.unam.mx/pub/Linux/Suse/isos/SLES11/ SLE-11-SP3-SDK-DVD-i586-GM-DVD1.iso 6deaa960 ...
- sunos kernel src leakrs
https://github.com/joede/libezV24 https://github.com/ysei/siriusSparcV8 https://github.com/omniti-la ...
- Javascript正则表达式详细讲解和示例,通俗易懂
正则表达式可以: •测试字符串的某个模式.例如,可以对一个输入字符串进行测试,看在该字符串是否存在一个电话号码模式或一个信用卡号码模式.这称为数据有效性验证 •替换文本.可以在文档中使用一个正则表达式 ...
- VO、DTO、DO、PO的概念、区别和用处
转至:http://qixuejia.cnblogs.com/ 本篇文章主要讨论一下我们经常会用到的一些对象:VO.DTO.DO和PO. 由于不同的项目和开发人员有不同的命名习惯,这里我首先对上述的概 ...
- 尽量用const,enum,inline代替define
在读<Effective C++>之前,我确实不知道const,enum,inline会和define扯上什么关系,看完感觉收获很大,记录之. define: 宏定义. 在编译预处理时,对 ...