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 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;
}

上一篇:北京太速科技-第六代Intel i7四核八线程6U VPX主控板


下一篇:Looksery Cup 2015 D. Haar Features 暴力