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 ...
随机推荐
- 生产线上的Nginx如何添加未编译安装模块
正在生产线上跑着web前端是nginx+tomcat,现在有这样一个需求,需要对网站的单品页面和列表页设置缓存,不同的页面设置不同的缓存,但是由于开始没有安装ngx_cache_purge这个模块,现 ...
- Netbeans调试教程
官方教程:Netbeans调试 CC++ 项目教程.docx 1.步过: 就是把函数当成一条指令来调用 比如上面就是光执行fun(i),不会到函数里面去 2.步入 就是进入函数里面执行 3.步出 就是 ...
- Markdown的安装和语法
步骤: 1.打开webstorm,File-->Setting-->输入plugin-->Install JetBrains plugin-->输入markdown--> ...
- Angular缺少 FormsModule
虽然 ngModel是一个有效的 Angular 指令,不过它在默认情况下是不可用的. 解决方法: 在根模块引入FormModule import { FormsModule } from '@ang ...
- CF666E Forensic Examination SAM+倍增,线段树和并
题面: 给你一个串S以及一个字符串数组T[1..m],q次询问,每次问S的子串S[p_l..p_r]在T[l..r]中的哪个串里的出现次数最多,并输出出现次数.如有多解输出最靠前的那一个. 分析: 第 ...
- Linux内核——进程管理之SMP负载均衡(基于版本4.x)
<奔跑吧linux内核>3.3笔记,不足之处还望大家批评指正 根据实际物理属性,CPU域分类如图1所示. 图1 CPU域分类 问题一:一个4核处理器中的每个物理CPU拥有独立L1 cach ...
- Ubuntu、CentOS 解决docker命令权限问题(sudo)
#创建docker组 weiyj@ubuntu18:~$ sudo groupadd docker groupadd: group 'docker' already exists #将当前用户加入do ...
- js事件 (包含call()方法使用特点)
1.焦点事件 获取焦点事件onfocus\失去焦点事件onblur 例: oText.onfocus=function(){} 焦点:使浏览器能够区分用户输入的对象,当一个元素有焦点的时候,那么它就可 ...
- HDU 2196 Computer(求树上每个点的最长距离)
题意: 这题想了挺久的, 参考了kuangbin大神的代码:https://www.cnblogs.com/kuangbin/archive/2012/08/28/2659915.html 给出树上边 ...
- 算法导论 第六章 2 优先队列(python)
优先队列: 物理结构: 顺序表(典型的是数组){python用到list} 逻辑结构:似完全二叉树 使用的特点是:动态的排序..排序的元素会增加,减少#和快速排序对比 快速一次排完 增 ...