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 [博弈论]
题面: 传送门 思路: 每一堆糖排成一列,所有列横着放,形成一个阶梯型 两个决策相当于左边一列去掉和最下面一行去掉 那么这个模型可以转化为同样形状的网格图,向左上方走,走到边界的赢· 然后一波数学推导 ...
随机推荐
- 虽然UIImageView是UIScollView的子视图,但UIImageView左上角是contentOfSet的原点
虽然UIImageView是UIScollView的子视图,但UIImageView左上角是contentOfSet的原点 https://www.evernote.com/shard/s22 ...
- python初步学习-python数据类型-字典(dict)
字典 字典类似于你通过联系人名字查找地址和联系人详细情况的地址簿,即,我们把键(名字)和值(详细情况)联系在一起.注意,键必须是唯一的,就像如果有两个人恰巧同名的话,你无法找到正确的信息. 注意,你只 ...
- 伪病毒 Rp_test
第一个写的对电脑有破坏性的程序= =,然后发现写system的copy的时候不会用字符串替代路径,然后就萎了= =,只能写一个没有自身复制的伪病毒了,坑到了好多同学的电脑,23333.... //By ...
- bzoj 3453 数论
首先我们知道对于f(x)来说,它是一个k次的多项式,那么f(x)的通项公式可以表示成一个k+1次的式子,且因为f(x)没有常数项,所以我们设这个式子为 f(x)=Σ(a[i]*x^i) (1<= ...
- recycleView实现item点击更改该item颜色,其它item颜色变回
项目中需要横向滚动效果,按照以前的思路,我会写一个ScrollView,里边加一个LinearLayout,在代码中动态加入控件,然后动态删除或者改变颜色,现在android有了新控件Recycler ...
- 【nginx】nginx的安装及测试
nginx中文文档:http://www.nginx.cn/doc/index.html 1.到官网下载nginx的压缩包: https://nginx.org/ 2.解压到相应的目录,比如我是e ...
- php中使用static方法
<?php class Char{ public static $number = 0; public static $name; function __construct($what){ se ...
- java多线程以及Android多线程
Java 多线程 线程和进程的区别 线程和进程的本质:由CPU进行调度的并发式执行任务,多个任务被快速轮换执行,使得宏观上具有多个线程或者进程同时执行的效果. 进程:在操作系统来说,一个运行的程序或者 ...
- Hadoop-MR[会用]MR程序的运行模式
1.简介 现在很少用到使用MR计算框架来实现功能,通常的做法是使用hive等工具辅助完成.但是对于其底层MR的原理还是有必要做一些了解. 2.MR客户端程序实现套路 这一小节总结归纳编写mr客户端程序 ...
- java 内部类和静态内部类的区别
private class InnerClass { // 只有在静态内部类中才能够声明或定义静态成员 // private static String tt = &quo ...