题目链接:http://codeforces.com/problemset/problem/549/C

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
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.

题解:

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

最新文章

  1. [嵌入式学习资料]ARM开发学习详解iTOP-4412开发板使用手册
  2. [转]数据库高可用架构(MySQL、Oracle、MongoDB、Redis)
  3. vue.js笔记
  4. leetcode 4 : Median of Two Sorted Arrays 找出两个数组的中位数
  5. Android开发 MMS支持 创建和编辑MMS
  6. python内置函数(4)
  7. 一台机器同时运行多个appium实例
  8. c++11 生产者/消费者
  9. shell的特殊符号的表示
  10. 解决airserver在Windows下安装失败的问题
  11. [补档]暑假集训D1总结
  12. 解决echarts饼图不显示数据为0的数据
  13. Oracle 条件判断函数decode和case when then案例
  14. ASP.NET MVC中使用FluentValidation验证实体(转载)
  15. java中List,Set,Map用法以及区别
  16. 22个值得收藏的Android开源代码——cool
  17. python读取文件首行和最后一行
  18. JAVA 实现 QQ 邮箱发送验证码功能(不局限于框架)
  19. java之 ------ 可变參数和卫条件
  20. 关于c# 发射的调用并进行缓存

热门文章

  1. for 、foreach 、iterator 三种遍历方式的比较
  2. Unix domain socket
  3. tomcat知识点
  4. 如何直接打开使用locate等查找到的文件
  5. 近期微信上非常火的小游戏【壹秒】android版——开发分享
  6. 【LeetCode-面试算法经典-Java实现】【002-Add Two Numbers (单链表表示的两个数相加)】
  7. java性能监控工具jps-windows
  8. PHP_EOL是什么意思?
  9. windows平台简易直播系统搭建
  10. 利用泛型和反射,管理配置文件,把Model转换成数据行,并把数据行转换成Model