Looksery Cup 2015 C. The Game Of Parity —— 博弈
题目链接:http://codeforces.com/problemset/problem/549/C
1 second
256 megabytes
standard input
standard output
There are n cities in Westeros. The i-th
city is inhabited by ai people.
Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all its residents, sadly, die. Stannis starts the game. The game ends when Westeros has exactly k cities
left.
The prophecy says that if the total number of surviving residents is even, then Daenerys wins: Stannis gets beheaded, and Daenerys rises on the Iron Throne. If the total number of surviving residents is odd, Stannis wins and everything goes in the completely
opposite way.
Lord Petyr Baelish wants to know which candidates to the throne he should support, and therefore he wonders, which one of them has a winning strategy. Answer to this question of Lord Baelish and maybe you will become the next Lord of Harrenholl.
The first line contains two positive space-separated integers, n and k (1 ≤ k ≤ n ≤ 2·105)
— the initial number of cities in Westeros and the number of cities at which the game ends.
The second line contains n space-separated positive integers ai (1 ≤ ai ≤ 106),
which represent the population of each city in Westeros.
Print string "Daenerys" (without the quotes), if Daenerys wins and "Stannis"
(without the quotes), if Stannis wins.
- 3 1
- 1 2 1
- Stannis
- 3 1
- 2 2 1
- Daenerys
- 6 3
- 5 20 12 7 14 101
- Stannis
In the first sample Stannis will use his move to burn a city with two people and Daenerys will be forced to burn a city with one resident. The only survivor city will have one resident left, that is, the total sum is odd, and thus Stannis wins.
In the second sample, if Stannis burns a city with two people, Daenerys burns the city with one resident, or vice versa. In any case, the last remaining city will be inhabited by two people, that is, the total sum is even, and hence Daenerys wins.
题解:
1.如果k==n,直接得出结果。
2.如果后手能把奇数城毁完,那么后手必胜(因为剩下的,不管怎么毁,总和都为偶数)。
3.如果后手不能把奇数城毁完,那么:
3.1. 如果倒数第二步操作的人不能把偶数城毁完,那么最后一步操作的人必胜,因为在最后一步时,既有奇数,也有偶数,可以随意调控。
3.2.如果倒数第二步操作的人能把偶数城毁完,那么剩下的就只有奇数城(或0),所以最后只需看剩下的奇数城有几座,即k。
代码如下:
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const double eps = 1e-6;
- const int INF = 2e9;
- const LL LNF = 9e18;
- const int mod = 1e9+7;
- const int maxn = 2e5+10;
- int n, k, a[2];
- void init()
- {
- scanf("%d%d",&n,&k);
- a[0] = a[1] = 0;
- for(int i = 1; i<=n; i++)
- {
- int x;
- scanf("%d",&x);
- a[x%2]++;
- }
- }
- void solve()
- {
- int winner;
- int step = n - k;
- if(step==0)
- winner = a[1]%2;
- else if(step/2>=a[1])
- winner = 0;
- else
- {
- if(step/2<a[0]) winner = step%2;
- else winner = k%2;
- }
- if(winner) puts("Stannis");
- else puts("Daenerys");
- }
- int main()
- {
- init();
- solve();
- }
Looksery Cup 2015 C. The Game Of Parity —— 博弈的更多相关文章
- codeforces Looksery Cup 2015 C. The Game Of Parity
There are n cities in Westeros. The i-th city is inhabited by ai people. Daenerys and Stannis play t ...
- Looksery Cup 2015 Editorial
下面是题解,做的不好.下一步的目标是rating涨到 1800,没打过几次cf A. Face Detection Author: Monyura One should iterate through ...
- Looksery Cup 2015 A. Face Detection 水题
A. Face Detection Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/pro ...
- Looksery Cup 2015 B. Looksery Party 暴力
B. Looksery Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/pro ...
- Looksery Cup 2015 D. Haar Features 暴力
D. Haar Features Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/prob ...
- Looksery Cup 2015 H. Degenerate Matrix 数学
H. Degenerate Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/ ...
- Looksery Cup 2015 F - Yura and Developers 单调栈+启发式合并
F - Yura and Developers 第一次知道单调栈搞出来的区间也能启发式合并... 你把它想想成一个树的形式, 可以发现确实可以启发式合并. #include<bits/stdc+ ...
- codeforces Looksery Cup 2015 H Degenerate Matrix
The determinant of a matrix 2 × 2 is defined as follows: A matrix is called degenerate if its determ ...
- codeforces Looksery Cup 2015 D. Haar Features
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viol ...
随机推荐
- 老哥你真的知道ArrayList#sublist的正确用法么
我们有这么一个场景,给你一个列表,可以动态的新增,但是最终要求列表升序,要求长度小于20,可以怎么做? 这个还不简单,几行代码就可以了 public List<Integer> trimL ...
- SG函数学习总结
有点散乱, 将就着看吧. 首先是博弈论的基础, 即 N 和 P 两种状态: N 为必胜状态, P 为必败状态. 对于N, P两种状态, 则有 1. 没有任何合法操作的状态, P; 2. 可以移动到P局 ...
- Ubuntu 16.04安装MongoDB的GUI工具RoboMongo
一.下载: https://robomongo.org/download 离线版本:(链接: https://pan.baidu.com/s/1mirFi56 密码: y3t2) 二.安装: -lin ...
- Nginx图片防盗链的方式
原文:http://www.open-open.com/code/view/1430750263460 location ~* \.(gif|jpg|jpeg|png|ico)$ { valid_re ...
- Swift oc 混编 - oc导入Swift协议
(默认已经设置好桥接头文件)1.在Swift文件中写好协议2.oc类文件中导入:"项目名-swift.h"格式的文件 即:#include "项目名-swift.h&qu ...
- js动态函数
最近项目中使用百度模板引擎baiduTemplate.js,使用动态函数解析模板中代码. 通过new Function([arg1,arg2,...,argN,]functionBody)方式实现动态 ...
- CrtmpServer getApplication注册流程
最近在研究 CrtmpServer getApplication注册流程,以备查阅 图1. 加载动态库流程 图2配置application流程
- C结构体对齐
函数模板针对仅参数类型不同的函数? http://blog.csdn.net/renrenhappy/article/details/5931457 计算结构体的大小就要考虑数据对齐问题. ...
- 实习日记 laravel怎么删除磁盘上的文件
Storage 里面有 delete的方法 具体使用是 Storage::disk('uploads')->delete($fileName); 其中'uploads'是filesystem里面 ...
- PHP中使用Redis
Redis是什么 Redis ( REmote DIctionary Server ) , 是一个由Salvatore Sanfilippo写的key-value存储系统. Redis是一个开源的使用 ...