C. The Game Of Parity
time limit per test
memory limit per test
input
output
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
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
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.
n space-separated positive integers ai (1 ≤ ai ≤ 106), which represent the population of each city in Westeros.
Output
Daenerys" (without the quotes), if Daenerys wins and "Stannis" (without the quotes), if Stannis wins.
Examples
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
1.首先若n == k则直接判断
2.若(n - k)为奇数,则最后一次操作的执行者是Stannis,此时要想Stannis赢,要么奇数和偶数都存在,要么奇数的个数为偶数个
3.若(n-k)为偶数,则最后一次操作的执行者是Daenerys,此时要想Stannis赢,那么只存在奇数,且奇数的个数为偶数个
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define MOD 1000000007
#define maxn 100005
using namespace std;
typedef long long ll;
int main(){
// freopen("in.txt", "r", stdin);
int n, k, odd = 0, even = 0, a;
scanf("%d%d", &n, &k);
for(int i = 0; i < n; i++){
scanf("%d", &a);
if(a&1)
odd++;
else
even++;
}
if(n == k){
if(odd&1)
puts("Stannis");
else
puts("Daenerys");
}
else{
int d = n - k - 1;
if(d % 2 == 0){
d /= 2;
if(even > d && odd > d)
puts("Stannis");
else if(d >= even && (odd - (2 * d - even)) % 2 == 0)
puts("Stannis");
else
puts("Daenerys");
}
else{
d /= 2;
d++;
if(d >= even && (odd - (d * 2 - 1 - even)) % 2 == 0)
puts("Stannis");
else
puts("Daenerys");
}
}
return 0;
}