codeforces Looksery Cup 2015 C. The Game Of Parity
2015-06-08 19:06
477 查看
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.
Input
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.
Output
Print string "Daenerys" (without the quotes), if Daenerys wins and "Stannis"
(without the quotes), if Stannis wins.
Sample test(s)
input
output
input
output
input
output
Note
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.
这道题属于博弈题,还是第一次做呢。。我看题解加代码,终于看明白了。。这题需分情况讨论,先读入n个数字,记录奇数的个数num1以及偶数的个数num2,第一种当n=k的时候,那么双方都不用破坏城市,所以就看总数的和是奇还是偶;第二种是如果num1<=(n-k)/2,也就是说一方能在自己走的步数中把奇数的个数都消灭掉,那么之后不管谁走,剩下的都是偶数了,总和一定是偶数,所以必定S胜利;第三种是如果num2<=(n-k)/2,这种情况比较难想,刚开始一直不清楚为什么某一方一定要先把偶数个数都消灭掉,难道先消灭几个奇数不行吗,后来想通了,因为不管是谁消灭掉所有偶数(可能是一个人消灭的,也有可能是两个人一起消灭的),其中k%2?S:D这一方有必胜法(仔细想想会明白的);最后一种是不管怎么消灭,最后剩下k个数的时候既有偶数又有奇数,那么这个时候最后一个走的人一定是胜利的,因为他可以看情况消灭偶数或奇数来得到偶数或奇数。
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.
Input
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.
Output
Print string "Daenerys" (without the quotes), if Daenerys wins and "Stannis"
(without the quotes), if Stannis wins.
Sample test(s)
input
3 1 1 2 1
output
Stannis
input
3 1 2 2 1
output
Daenerys
input
6 3 5 20 12 7 14 101
output
Stannis
Note
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.
这道题属于博弈题,还是第一次做呢。。我看题解加代码,终于看明白了。。这题需分情况讨论,先读入n个数字,记录奇数的个数num1以及偶数的个数num2,第一种当n=k的时候,那么双方都不用破坏城市,所以就看总数的和是奇还是偶;第二种是如果num1<=(n-k)/2,也就是说一方能在自己走的步数中把奇数的个数都消灭掉,那么之后不管谁走,剩下的都是偶数了,总和一定是偶数,所以必定S胜利;第三种是如果num2<=(n-k)/2,这种情况比较难想,刚开始一直不清楚为什么某一方一定要先把偶数个数都消灭掉,难道先消灭几个奇数不行吗,后来想通了,因为不管是谁消灭掉所有偶数(可能是一个人消灭的,也有可能是两个人一起消灭的),其中k%2?S:D这一方有必胜法(仔细想想会明白的);最后一种是不管怎么消灭,最后剩下k个数的时候既有偶数又有奇数,那么这个时候最后一个走的人一定是胜利的,因为他可以看情况消灭偶数或奇数来得到偶数或奇数。
#include<iostream> #include<stdio.h> #include<string.h> #include<math.h> #include<vector> #include<map> #include<queue> #include<stack> #include<string> #include<algorithm> using namespace std; int a[200006]; int main() { int n,m,k,i,j,num1,num2; while(scanf("%d%d",&n,&k)!=EOF) { num1=num2=0; for(i=1;i<=n;i++){ scanf("%d",&a[i]); if(a[i]%2==1)num1++; else num2++; } if(num1+num2==k){ if((num1+num2*2)%2==1){ printf("Stannis\n");continue; } else{ printf("Daenerys\n");continue; } } if(num1<=(n-k)/2){ printf("Daenerys\n");continue; } if(num2<=(n-k)/2){ if(k%2==1){ printf("Stannis\n");continue; } else{ printf("Daenerys\n");continue; } } if((n-k)%2==1){ printf("Stannis\n");continue; } else{ printf("Daenerys\n");continue; } } return 0; }
相关文章推荐
- 每天一个linux命令(58):telnet命令
- 七大排序算法
- opencv pcl confict 冲突
- eclipse下Tomcat7.0启动奔溃问题
- ios常用的基础框架
- java.lang.OutOfMemoryError问题的解决方法
- Mysql 监控工具 – mytop
- 虚函数的内部实现机制
- Linux文件查找命令find详述
- 小度WiFi作为无线网卡设置的方法
- 解决Windows x64bit环境下无法使用PLSQL Developer连接到Oracle DB中的问题
- linux内核树的建立
- mysql 优化 实现命中率100%
- 缓存机制 Cache ARC算法(二)
- 计算机专业学生必看的网站
- AutoLayout +Masonary
- Ubuntu 系统的降温方案
- 【Cocos游戏实战】功夫小子第三课之过渡场景和开始菜单的实现
- 服务号微信订阅号是否要合并了?服务号要被集中到订阅列表中
- 在WEB.xml文件中配置Spring容器