博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AtCoder - 1999 Candy Piles
阅读量:5459 次
发布时间:2019-06-15

本文共 1788 字,大约阅读时间需要 5 分钟。

Problem Statement

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:

  1. Choose a pile with the largest number of candies remaining, then eat all candies of that pile.
  2. 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:

Na1 a2 … aN
Output

If Snuke will win, print First. If Ciel will win, print Second.

Sample Input 1
21 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
31 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
31 2 3
Sample Output 3
Second (假设高度有序,从左到右递减)     可以把问题转化成,初始在(0,0),有n个矩形拼成的凸多边形,第i个矩形是的左下角是(i-1,0),右上角是(i,h[i])。那么游戏就相当于每次只能向右或者向上走,不能走出多边形,问先手是否必胜。     可以先画一画1*1的小正方形的情况,可以发现不论右上角是什么状态,左下角一定和它的状态一样 (右上角必败比较好发现,必胜的话要多画几个其他点的状态)。     于是就可以直接暴力做了2333
#include
#define ll long longusing 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;}

 

 

转载于:https://www.cnblogs.com/JYYHH/p/9250505.html

你可能感兴趣的文章
P4302 [SCOI2003]字符串折叠
查看>>
神秘的程序员
查看>>
jS 中创建对象:
查看>>
zless轻量级样式框架
查看>>
ZeroMQ接口函数之 :zmq_term - 终结ZMQ环境上下文(context)
查看>>
js获取倒计时
查看>>
loadrunner安装过程中的,注册表问题
查看>>
git push失败the remote end hung up unexpectedly
查看>>
POJ3087 Shuffle'm Up 简单模拟
查看>>
Django中数据的增删改查
查看>>
iOS模拟器发生了崩溃,去哪找Crash Log
查看>>
[支付宝]即时到账接口对接总结
查看>>
夺命雷公狗-----React---15--三元运算符
查看>>
元首的愤怒 SharePoint Apps
查看>>
CSS
查看>>
两个DataGrid垂直滚动条同步滚动
查看>>
RPG的错排
查看>>
Java 7之基础 - 强引用、弱引用、软引用、虚引用
查看>>
位运算
查看>>
微软源代码管理工具TFS2013安装与使用图文教程
查看>>