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 ...
随机推荐
- ubuntu下安装apcu扩展
apcu前身是apc,apc分为系统缓存和用户缓存 1.系统缓存是指PHP执行时增加缓存,减少PHP文件的反复检查和编译,从而达到系统加速的目的. 2.用户缓存是指,PHP代码中将数据写入缓存,是用户 ...
- jq获取设置选中值
var standard = $('input[name="standard"]:checked').val(); $("input[name='advertByid'] ...
- 借助tween.js小球沿div四边跑的动画效果
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- phpstorm 格式化代码
MAC 安装phpcs.phpcbf composer global require 'squizlabs/php_codesniffer=*' Changed current directory t ...
- Eclipse被卡死了或者失去响应了后分析根源的一个小技巧
提升程序员工作效率的工具/技巧推荐系列 推荐一个功能强大的文件搜索工具SearchMyFiles 介绍一个好用的免费流程图和UML绘制软件-Diagram Designer 介绍Windows任务管理 ...
- uva1228 Integer Transmission
这道题思维很灵活.也有点套路的意思. 首先规定0,1分别按照原来的顺序接收,只是01换位.这样简化了思维.(否则并不会有更优结果它.,比较好想)最大值和最小值可以贪心得到.那么接下来就是给定一个整数P ...
- Hibernate中tx.commit()
hibernate.cfg,xml文件中的自动提交事务是false.主键生成策略是native. 在表的映射继承是手动提交事务(即:tx.commit())无法发出sql语句,把数据插入到数据库的表中 ...
- 对数组内容使用了json_encode返回汉字内容返回了空值
如果使用json_encode对数组进行转成JSON字符串时候,发现汉字的全部为空,这样可以说明的一点是你的页面上用的一定不是UTF8编码,在PHP手册中对json_encode中待编码的值已经说明所 ...
- 常见的linux命令及其翻译
常见的linux指令 1.ls ll 查看文件信息 2.cd 切换工作目录 cd 或 cd ~ 切换到/home/用户目录 cd. 切换到当前目录 cd.. 切换到上级目录 cd- 切换入上次所在的目 ...
- 【Java IO流】浅谈io,bio,nio,aio
本文转载自:http://www.cnblogs.com/doit8791/p/4951591.html 1.同步异步.阻塞非阻塞概念 同步和异步是针对应用程序和内核的交互而言的. 阻塞 ...