codeforces Looksery Cup 2015 C. The Game Of Parity
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个数字,记录奇数的个数num1以及偶数的个数num2,第一种当n=k的时候,那么双方都不用破坏城市,所以就看总数的和是奇还是偶;第二种是如果num1<=(n-k)/2,也就是说一方能在自己走的步数中把奇数的个数都消灭掉,那么之后不管谁走,剩下的都是偶数了,总和一定是偶数,所以必定S胜利;第三种是如果num2<=(n-k)/2,这种情况比较难想,刚开始一直不清楚为什么某一方一定要先把偶数个数都消灭掉,难道先消灭几个奇数不行吗,后来想通了,因为不管是谁消灭掉所有偶数(可能是一个人消灭的,也有可能是两个人一起消灭的),其中k%2?S:D这一方有必胜法(仔细想想会明白的);最后一种是不管怎么消灭,最后剩下k个数的时候既有偶数又有奇数,那么这个时候最后一个走的人一定是胜利的,因为他可以看情况消灭偶数或奇数来得到偶数或奇数。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
int a[200006];
int main()
{
int n,m,k,i,j,num1,num2;
while(scanf("%d%d",&n,&k)!=EOF)
{
num1=num2=0;
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]%2==1)num1++;
else num2++;
}
if(num1+num2==k){
if((num1+num2*2)%2==1){
printf("Stannis\n");continue;
}
else{
printf("Daenerys\n");continue;
}
}
if(num1<=(n-k)/2){
printf("Daenerys\n");continue;
}
if(num2<=(n-k)/2){
if(k%2==1){
printf("Stannis\n");continue;
}
else{
printf("Daenerys\n");continue;
}
}
if((n-k)%2==1){
printf("Stannis\n");continue;
}
else{
printf("Daenerys\n");continue;
}
}
return 0;
}
codeforces Looksery Cup 2015 C. The Game Of Parity的更多相关文章
- codeforces Looksery Cup 2015 H Degenerate Matrix
The determinant of a matrix 2 × 2 is defined as follows: A matrix is called degenerate if its determ ...
- codeforces Looksery Cup 2015 D. Haar Features
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viol ...
- codeforces Looksery Cup 2015 H Degenerate Matrix 二分 注意浮点数陷阱
#include <cstdio> #include <cstring> #include <algorithm> #include <string> ...
- Looksery Cup 2015 C. The Game Of Parity —— 博弈
题目链接:http://codeforces.com/problemset/problem/549/C C. The Game Of Parity time limit per test 1 seco ...
- Looksery Cup 2015 A. Face Detection 水题
A. Face Detection Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/pro ...
- Looksery Cup 2015 B. Looksery Party 暴力
B. Looksery Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/pro ...
- Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)
题目链接:http://codeforces.com/contest/522/problem/D 题目大意: 给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...
- Looksery Cup 2015 D. Haar Features 暴力
D. Haar Features Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/prob ...
- Looksery Cup 2015 H. Degenerate Matrix 数学
H. Degenerate Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/ ...
随机推荐
- c++ 参数传递与返回值详解(reference)
pass by value or pass by reference? 我们知道,当函数在传递值的时候,会新建一个变量(没有名字)储存这个值 然后传递.降低程序运行的效率. 如果使用引用(refere ...
- MySQL select if 查询最后一个主键 id
查询最后一个主键id SELECT IF(MAX(id) IS NULL, 0, MAX(id)) AS maxid FROM users; 查询最小的主键id SELECT IF(MIN(id) I ...
- 使用msys2在window下构建和使用Linux的软件
目录 前言 安装 使用 总结 前言 在window下构建Linux编译环境是很常见的,以前用过mingw弄过差不多的环境. 但是使用msys2后就根本停不下来咯,太好用咯. 安装 去官网下载吧,安装跟 ...
- 【Linux】NFS搭建及使用详解
环境:CentOS release 6.8 server 192.168.25.100 client1 192.168.25.101 client2 192.168.25.102 1.服务端操作 1 ...
- 惠普电脑(HP PHILIPS系列)安装ubuntu后无法连接WIFI解决方案(手动安装8821CE驱动)
一步一步来, 先说环境: 我的电脑是HP PHILIPS系列,ubuntu版本是16.04 背景: win10安装ubuntu后发现无法连接wifi(但win10系统可以连接WIFI),在ubuntu ...
- 基于kubernetes实现coredns的及验证
CoreDNS: k8s内部的DNS ,用于对pod对service做记录的,好让其他的pod做访问 这里不用做过多的阐述 官方kube-dns现在已经没有在维护了,从Kubernetes 1.11 ...
- 工作记录:记一次线上ZK掉线问题排查
目录 问题的发现 zk的情况以及分析 总结 问题的发现 最早问题的发现在于用户提的,用户提出他支付时支付失败,过了一会儿再试就好了,于是翻日志,查询到当时duboo调用出现了下类错误: [TraceI ...
- VBScript调用winscp,实现sftp操作
最新有一个需求,需要在ssis中调用sftp下载文件,由于服务器上只有framework2.0,并且需要用sqlserver代理调用作业,限制了很多. 首先用的是脚本任务,进程调用winscp.com ...
- SYSTEM_SHMCONSTR_LOGON_FAILED错误解决办法
如果你在调用WebDynpro程序时,发现st22里有如上图所示的报错信息,可以参考note:1318269所列举的方法来进行处理.大概的方法就是,通过SE80,执行任意的webdypro程序,例如& ...
- layui表格前端格式化时间戳字段
layui.use(['util','table'], function(){ var table = layui.table; var util = layui.util; //... ...