Codeforces 549C(博弈)
1 second
256 megabytes
standard input
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.
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.
Print string "Daenerys" (without the quotes), if Daenerys wins and "Stannis" (without the quotes), if Stannis wins.
3 1
1 2 1
Stannis
3 1
2 2 1
Daenerys
6 3
5 20 12 7 14 101
Stannis
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个城市,如果剩下的k个城市的人数和是奇数,那么先手赢,否则后手赢。
思路:
如果后手能够有机会屠掉所有奇数城,那么先手必败。
如果有奇数城剩余,继续考虑如果要屠的城为奇数座,那么先手可以最后利用偶数城,调整当前奇数城的数量,必胜。
但是如果后手能够将偶数城全部干掉,那么最后就变成看剩下的k是奇数还是偶数了。
如果要杀偶数个城,那么后手可以做最后调整,如果先手杀不光偶数城,那么后手必胜,如果先手能杀光偶数城,
那么结果就看剩下的k是奇数还是偶数了。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
int n,k,a[];
int main()
{
scanf("%d%d",&n,&k);
int i,cnt=;
for (i=;i<=n;i++)
{
int x;
scanf("%d",&x);
if (x&) cnt++;
}
int num2=(n-k)>>;
int num1=(n-k+)>>;
bool fg=true;
if (cnt<=num2)
fg=false;
if (k%==&&n-cnt<=num2)
fg=false;
if ((n-k)%==)
{
if ((num1>=n-cnt&&k%)==false)
fg=false;
}
if (n==k)
fg=(cnt&)?true:false;
puts(fg?"Stannis":"Daenerys");
return ;
}
Codeforces 549C(博弈)的更多相关文章
- Codeforces 549C The Game Of Parity【博弈】
C语言纠错大赛的一道题,正好拿来补博弈~~ 给的代码写的略奇葩..不过还是直接在上面改了.. 题目链接: http://codeforces.com/problemset/problem/549/C ...
- Codeforces 549C The Game Of Parity(博弈)
The Game Of Parity Solution: 这个题只需要分类讨论就可以解决. 先分别统计奇数和偶数的个数. 然后判断谁走最后一步,如果走最后一步时候同时有偶数和奇数,那么走最后一步的赢. ...
- Codeforces 549C. The Game Of Parity[博弈论]
C. The Game Of Parity time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces 354B 博弈, DP,记忆化搜索
题意:现在有一个字符矩阵,从左上角出发,每个人交替选择一个字符.如果最后字符a数目大于字符b,那么第一个人获胜,否则b获胜,否则平均.现在双方都不放水,问最后结果是什么? 思路:这题需要注意,选择的字 ...
- Ticket Game CodeForces - 1215D 博弈题
题目描述 Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even ...
- ACM 博弈(难)题练习 (第一弹)
第二弹: 套路&&经验总结: 1. N堆***的游戏,一般可以打表找SG函数的规律.比如CodeForces 603C 2.看起来是单轮的游戏,实际上可能拆分成一些独立的子游戏.比如C ...
- Codeforces 455B A Lot of Games(字典树+博弈)
题目连接: Codeforces 455B A Lot of Games 题目大意:给定n.表示字符串集合. 给定k,表示进行了k次游戏,然后是n个字符串.每局開始.字符串为空串,然后两人轮流在末尾追 ...
- CodeForces 1099F - Cookies - [DFS+博弈+线段树]
题目链接:https://codeforces.com/problemset/problem/1099/F Mitya and Vasya are playing an interesting gam ...
- codeforces 812E Sagheer and Apple Tree(思维、nim博弈)
codeforces 812E Sagheer and Apple Tree 题意 一棵带点权有根树,保证所有叶子节点到根的距离同奇偶. 每次可以选择一个点,把它的点权删除x,它的某个儿子的点权增加x ...
随机推荐
- NestedScrollView嵌套RecycleView发生的小问题
1.解决方法:嵌套滑动不激活. recycleView.setNestedScrollingEnable(false); 这样做有个弊端,RecycleView的item会一次性加载完,不管是否显示, ...
- 一个Java编写的小玩意儿---多人在线聊天工具
这个在线聊天工具小项目使用JAVA编写,用JAVA来做图形界面本来就是出了名的低效和丑陋.不过这不是重点.写这个小项目的目的在于串一串J2SE的知识,把当时写这个项目的时候的思路梳理一下.时间有点久了 ...
- 导入Excel表格(二)
1. 提取session中的数据.并进行分页操作,上传excel表格,保存到临时表格. 初始化临时表格,提交表单,判断状态是否为真,若为真,则启用 导入到数据库 的按钮:为false,让查询的url ...
- 解决Homestead yarn , npm run dev, 命令报错问题!
解决Homestead yarn , npm run dev, 命令报错问题! 2018年06月01日 11:50:51 偶尔发发颠 阅读数:1654 版权声明:本文为博主原创,未经博主同意,不 ...
- matlab 随笔
<<matlab高级编程技巧与应用:45个案例分析>> 一. 重新认识向量化编程 1.向量化编程与循环的比较 2.预分配内存更好 3.matlab中是列优先 4.归一化 数据归 ...
- Tomcat启动报错 ERROR org.apache.struts2.dispatcher.Dispatcher - Dispatcher initialization failed
背景: 在进行Spring Struts2 Hibernate 即SSH整合的过程中遇到了这个错误! 原因分析: Bean已经被加载了,不能重复加载 原来是Jar包重复了! 情形一: Tomcat ...
- java list去重操作实现方式
Java中的List是可以包含重复元素的(hash code 和equals),接下来将介绍两种方式实现java list去重操作,感兴趣的朋友可以参考下 Java中的List是可以包含重复元素的 ...
- MySQL学习点滴 --分区表
写在前面:笔者之前也有一些MySQL方面的笔记,其中部分内容来自极客时间中丁奇老师的课程.后经园友提醒,这个做法确实不太好.之后我仍会继续更新一下MySQL方面的学习记录,在自己理解之后用自己的方式记 ...
- php file_get_contents json_decode 输出为NULL
解决办法一:不小心在返回的json字符串中返回了BOM头的不可见字符,某些编辑器默认会加上BOM头,如下处理才能正确解析json数据: $info = json_decode(trim($info,c ...
- InnoDB透明页压缩与稀疏文件
此文已由作者王慎为授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. MySQL 5.7中包括了很多让人耳目一新的新特性,其中就包括了InnoDB Transparent Pag ...