Codeforces 549C The Game Of Parity

C. The Game Of Parity
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

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.

Examples
input
Copy
 
         
3 1
1 2 1
output
Copy
Stannis
input
Copy
 
         
3 1
2 2 1
output
Copy
Daenerys
input
Copy
 
         
6 3
5 20 12 7 14 101
output
Copy
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座城市,Stannis 和 Westeros先后消灭一座城市,消灭到剩下k座城市的时候,如果这k座城市的人口总数为奇数
Stannis赢,为偶数W赢,询问是否有先手必胜策略

分析:  如果剩下的k座城市人口全为偶数则人口总数肯定是偶数W赢,如果为奇数的话需要讨论k的奇偶性。所以先判断能否把奇数的城市全都消灭完。如果不能的话,看一下能否在有限的步骤内把人口为偶数的城市消灭完,如果可以的话,剩下的都是奇数人口的城市,如果k是偶数则必定是偶数,反之为奇数。如果不可以,说明偶数人口和奇数人口的城市均会剩下,这个时候走最后一步的人会根据对手调整策略达到必胜。总之这种情况判断一下可以操作的步骤奇偶性就行了。注意没有城市被消灭的情况特判。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int odd = 0,even = 0;
    for(int i = 1; i <= n; i++)
    {
        int x;cin>>x;
        if(x % 2 == 1)
            odd++;
        else
            even++;
    }
    int f = 0;
    int r = n - k;
    if(r / 2 >= odd)
        f = 0;
    else
    {
        if(r == 0)
        {
            if(odd % 2 == 1)
                f = 1;
            else
                f = 0;
        }
        else
        {
            if(r % 2 == 1)
        {
            if((k % 2 == 0) && (r / 2 >= even))
                f = 0;
            else f = 1;
        }
        else
        {
            if((k % 2 == 1) && (r / 2 >= even))
                f = 1;
            else
                f = 0;
        }
        }
    }
    if(f == 1)printf("Stannis\n");
    else printf("Daenerys\n");
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值