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 [博弈论]
题面: 传送门 思路: 每一堆糖排成一列,所有列横着放,形成一个阶梯型 两个决策相当于左边一列去掉和最下面一行去掉 那么这个模型可以转化为同样形状的网格图,向左上方走,走到边界的赢· 然后一波数学推导 ...
随机推荐
- Spring4+SpringMVC+MyBatis整合思路(山东数漫江湖)
1.Spring框架的搭建 这个很简单,只需要web容器中注册org.springframework.web.context.ContextLoaderListener,并指定spring加载配置文件 ...
- Codeforces Round #482 (Div. 2) B题
题目链接:http://codeforces.com/contest/979/problem/B B. Treasure Hunt time limit per test1 second memory ...
- 【转】jpg文件格式详解
JPEG(Joint Photographic Experts Group)是联合图像专家小组的英文缩写.它由国际电话与电报咨询委员会CCITT(The International Telegraph ...
- vue基本介绍
https://cn.vuejs.org/v2/guide/ Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上 ...
- Keepalived 安装与简单配置
Keepalived 安装与简单配置 http://sivxy.lofter.com/post/1d21ebb9_7e15000
- python 使用headless chrome滚动截图
from selenium import webdriver from selenium.webdriver.chrome.options import Options import util chr ...
- 007 Java并发编程:Callable、Future和FutureTask
原文https://www.cnblogs.com/dolphin0520/p/3949310.html Java并发编程:Callable.Future和FutureTask 在前面的文章中我们讲述 ...
- C C++ 常被人问的问题分析
正文 - 开始了, 直接扯淡 以下都是自己面试中遇到的常见的问题.如有不妥的地方就当见笑了. 哈哈 1. 谈谈你们服务器的架构吧. 分析: 假如这是第一个问题, 你可以走了. 可能各方面原因他不想 ...
- HIbernate学习笔记1 之 简介
一.Hibernate的概念 hibernate是数据访问层的框架,对JDBC进行了封装,是针对数据库访问提出的面向对象的解决方案.使用它可以直接访问对象,自动将此访问转换为SQL执行,从而达到间接访 ...
- C++智能指针: auto_ptr, shared_ptr, unique_ptr, weak_ptr
本文参考C++智能指针简单剖析 内存泄露 我们知道一个对象(变量)的生命周期结束的时候, 会自动释放掉其占用的内存(例如局部变量在包含它的第一个括号结束的时候自动释放掉内存) int main () ...