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
  1. 3 1
    1 2 1
output
  1. Stannis
input
  1. 3 1
    2 2 1
output
  1. Daenerys
input
  1. 6 3
    5 20 12 7 14 101
output
  1. 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座城人数有奇有偶,最后留下k座,偶的话我龙母win,奇的话史坦利斯win


很明显的博弈论,然而一直没有认真学过,想了想有点萌

  1. 官方题解
  2. C. The Game Of Parity
  3. Author: olpetOdessaONU
  4. If n = k no moves may be done. The winner is determined with starting parity of citizens' number. Otherwise let's see that the player making the last move may guarantee his victory, if there are both odd and even cities when he makes the move. He just selects the city of which parity he should burn to obtain required parity. So, his enemy's target is to destroy all the cities of some one type. Sometimes the type does matter, sometimes doesn't. It depends on the player's name and the parity of k. So the problem's solution consists in checking if "non-last" player's moves number (n - k) / 2 is enough to destroy all the odd or even cities. If Stannis makes the last move and k is even, Daenerys should burn all the odd or all the even cities. If k is odd, Daenerys should burn all the odd cities. If Daenerys makes the last move and k is even, Stannis has no chance to win. If k is odd, Stannis should burn all the even cities.

奇+奇=偶,偶+偶=偶,奇+偶=奇

只要最后剩下奇和偶,那么最后一个人一定赢,最后一次取可以改变奇偶也可以不改变

所以分情况讨论另一个人能不能把某种奇偶性杀完行了

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6. typedef long long ll;
  7. const int N=2e5+;
  8. ll read(){
  9. char c=getchar();ll x=,f=;
  10. while(c<''||c>''){if(c=='-')f=-; c=getchar();}
  11. while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
  12. return x*f;
  13. }
  14. ll n,k,a,sum,odd,even,lo,r[],win;//0 D 1 S
  15. void game(){
  16. if(n==k){if(sum%==) win=;else win=;return;}
  17.  
  18. r[]=r[]=(n-k)/;
  19. if((n-k)%==) lo=;
  20. else lo=,r[]++;
  21.  
  22. if(lo==){
  23. win=;
  24. if(k%==)
  25. if(r[]>=odd||r[]>=even){win=;return;}
  26. if(k%==)
  27. if(r[]>=odd){win=;return;}
  28. }else{
  29. win=;
  30. if(k%==) return;
  31. if(k%==)
  32. if(r[]>=even){win=;return;}
  33. }
  34. }
  35. int main(int argc, const char * argv[]) {
  36. n=read();k=read();
  37. for(int i=;i<=n;i++){
  38. a=read(); sum+=a;
  39. if(a%==) even++;
  40. else odd++;
  41. }
  42. game();
  43. cout<<(win?"Stannis":"Daenerys");
  44. return ;
  45. }

Codeforces 549C. The Game Of Parity[博弈论]的更多相关文章

  1. Codeforces 549C The Game Of Parity(博弈)

    The Game Of Parity Solution: 这个题只需要分类讨论就可以解决. 先分别统计奇数和偶数的个数. 然后判断谁走最后一步,如果走最后一步时候同时有偶数和奇数,那么走最后一步的赢. ...

  2. Codeforces 549C The Game Of Parity【博弈】

    C语言纠错大赛的一道题,正好拿来补博弈~~ 给的代码写的略奇葩..不过还是直接在上面改了.. 题目链接: http://codeforces.com/problemset/problem/549/C ...

  3. Codeforces 979E Kuro and Topological Parity - 动态规划 - 组合数学

    题目传送门 传送点 题目大意 给定$n$个标号依次为$1, 2, \cdots, n$的点,其中一些点被染成一些颜色,剩下的点没有染色.你需要添加一些有向边并将剩下的点染色,满足有向边从编号小的一端指 ...

  4. codeforces 1451D,一道有趣的博弈论问题

    大家好,欢迎来到codeforces专题. 今天选择的问题是Contest 1451场的D题,这是一道有趣简单的伪博弈论问题,全场通过的人有3203人.难度不太高,依旧以思维为主,坑不多,非常友好. ...

  5. Codeforces 549C(博弈)

    C. The Game Of Parity time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. Codeforces 979E Kuro and Topological Parity(dp)

    题面传送门 题意:有 \(n\) 个点,每个点要么被涂黑,要么被涂白,要么没有颜色. 现在你要: 给没有颜色的点图上颜色(黑色或白色) 在这 \(n\) 个点中连若干条有向边,可以不连通.但是只能从编 ...

  7. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  8. ACM 博弈(难)题练习 (第一弹)

    第二弹: 套路&&经验总结: 1. N堆***的游戏,一般可以打表找SG函数的规律.比如CodeForces 603C 2.看起来是单轮的游戏,实际上可能拆分成一些独立的子游戏.比如C ...

  9. CF55C. Pie or die

    /* CF55C. Pie or die http://codeforces.com/problemset/problem/55/C 博弈论 乱搞 获胜条件是存在一个棋子到边界的值小于5 */ #in ...

随机推荐

  1. Eclipse spket插件 内置js文件

    这一篇将怎么在spket内置js文件,而不用用户自己去添加.    1. 在开发的Eclipse的 运行配置将下面几个插件勾选上.     2. 在org.eclipse.ui.startup拓展里执 ...

  2. 读《数据结构与算法 Javascript描述》 | 平淡无奇

    “平淡无奇”,一句话总结. 当初买这本书的原因,在意的是有没有什么令人惊喜的东西,特别是针对Javascript代码的奇思妙想,所以就买下了这本书. 在买的几本书里面,最先看的也是这一本,但看起目录就 ...

  3. pip安装教程

    首先你得安装了Python,这个网上教程大把. 关于pip的安装教程网上也很多,但是安装过程中遇到了很多问题. 我把安装pip需要的资源都放到云盘上了,直接下载就行,省得去找.(点我下载) 里面有两个 ...

  4. ABAP--关于ABAP流程处理的一些命令的说明(stop,exit,return,check,reject)

    Stop 命令 使用该命令的程序位置 INITIALIZATION, AT SELECTION-SCREEN, START-OF-SELECTION和GET 事件中 处理说明 1. 当在INITIAL ...

  5. SharePoint Online 创建门户网站系列之创建栏目

    前 言 SharePoint Online的栏目,简单描述即显示在首页上的各个模块信息,这里,我们主要介绍我们首页上的栏目,包括简介类型.新闻列表类型.图片类型: 下面,让我们开始在SharePoin ...

  6. exec

    之前一直这样显示 不知道修改了什么,变成了这样. 在终端   找到这个podfile所在的目录 chmod 600 podfile   然后 就变回来了.可能是修改权限的问题.

  7. iOS中如何知道app版本已更新

    主要用于程序升级,开启程序后是否显示新特性两个方面. 1.苹果app版本 苹果规定,程序的版本只能升不能降.例如1.0->1.1可以,1.1->1.0就不可以,不允许上架. 2.app版本 ...

  8. iOS--(UITableViewCell)、(UITableViewController)微信个人主页

    本文主要实现了微信的个人主页的设置: 目录文件如下: 实现代码如下: RootTableViewController.h #import <UIKit/UIKit.h> @interfac ...

  9. 在SQL2008中使用XML应对不确定结构的参数

    目的:统一接口,当数据结构发生变化时,前后端业务接口不发生变化,由业务具体解析结构. 规则:确定的接口用参数表(多行提交),不确定的参数用XML   DECLARE @r TABLE     (    ...

  10. php设计模式 工厂、单例、注册树模式

    Source Code Pro字体  easyphp 命名空间:隔离类和函数,php5.3以后 //test5.php<?php namespace Test5;//命名空间必须是程序脚本的第一 ...