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 [博弈论]
题面: 传送门 思路: 每一堆糖排成一列,所有列横着放,形成一个阶梯型 两个决策相当于左边一列去掉和最下面一行去掉 那么这个模型可以转化为同样形状的网格图,向左上方走,走到边界的赢· 然后一波数学推导 ...
随机推荐
- 【洛谷 P2742】【模板】二维凸包
题目链接 二维凸包板子..有时间会补总结的. #include <cstdio> #include <cmath> #include <algorithm> usi ...
- 广度优先算法(BFS)与深度优先算法(DFS)
一.广度优先算法BFS(Breadth First Search) 基本实现思想 (1)顶点v入队列. (2)当队列非空时则继续执行,否则算法结束. (3)出队列取得队头顶点v: (4)查找顶点v的所 ...
- 【DLL】动态库的创建,隐式加载和显式加载(转)
原文转自:https://blog.csdn.net/dcrmg/article/details/53437913
- Python大牛开小灶,一对一问答
CSDN知识小饭桌 大牛开小灶 小范围,高质量,在线交流QA 参与嘉宾 知识库特邀编辑伊海波,滴滴出行工程师,曾任龙图龙图游戏数据分析部技术负责人.CSDN博客专家,资深Python/Golang ...
- LCD 每隔10分钟 自动熄灭 --打开Framebuffer console的时候【转】
转自:http://blog.csdn.net/liujia2100/article/details/9009063 版权声明:本文为博主原创文章,未经博主允许不得转载. 之前移植LCD的时候,一切正 ...
- xxx_initcall相关知识
参考文件include/linux/init.h /* * Early initcalls run before initializing SMP. * * Only for built-in cod ...
- Linux内核【链表】整理笔记(2) 【转】
转自:http://blog.chinaunix.net/uid-23069658-id-4725279.html 关于链表我们更多时候是对其进行遍历的需求,上一篇博文里我们主要认识了一下和链表操作比 ...
- opengl基础学习专题 (一 )编程环境搭建
题外话: 第一次在博客园上同大家分享博文.水的的地方,错别字的地方.环境交流.批评.知道了马上改. 以前在百度空间中写技术分享博文,后来百度啥也没说就把整个空间封了.当时感觉 还是有点寒心.只想黑一下 ...
- Linux设备驱动--内存管理
MMU具有物理地址和虚拟地址转换,内存访问权限保护等功能.这使得Linux操作系统能单独为每个用户进程分配独立的内存空间并且保证用户空间不能访问内核空间的地址,为操作系统虚拟内存管理模块 ...
- echo常用操作
echo -n 不换行输出 [root@C ~]# echo -n "peter" ; echo "linux" peterlinux echo -e 输出转义 ...