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/ ...
随机推荐
- 剑指offer-56数组中数字出现的次数
题目 一个整型数组 nums 里除两个数字之外,其他数字都出现了两次.请写程序找出这两个只出现一次的数字.要求时间复杂度是O(n),空间复杂度是O(1). 输入:nums = [4,1,4,6] 输出 ...
- 【Tomcat 源码系列】认识 Tomcat
一,前言 说一句大实话,"平时一直在用 Tomcat,但是我从来没有用过 Tomcat". "平时一直在用 Tomcat",是因为搬砖用的 SpringBoot ...
- maven仓库和镜像
目录 简介 本地仓库 远程仓库 远程仓库的更新 远程仓库的认证 部署到远程仓库 快照版本 依赖解析 镜像 本文主要是针对<maven实战>书中关键知识点的学习记录,未免有纰漏或描述不到之处 ...
- SQL Server解惑——查询条件IN中能否使用变量
在SQL Server的查询条件中,能否在IN里面使用变量呢? 如果可以的话,有没有需要注意的地方或一些限制呢?在回答这个问题前,我们先来看看这个例子: IF EXISTS (SELECT 1 FRO ...
- Windows程序通用自动更新模块(C#,.NET4.5以上)
本通用自动更新模块适合所有Windows桌面程序的自动更新,不论语言,无论Winform还是wpf. 一.工作流程:1. 主程序A调起升级程序B2. B从服务器获取更新程序列表,打印更新信息.3. B ...
- 误删除SAP ECC中的profile文件
环境:ECC6.0 EHP4 FOR ORACLE ON WINDWS X64下 今天在RZ10配置系统参数文件的时候,不小心错删除了instance profile文件,这下惨了,这是操作系统层级 ...
- AWS IoT Greengrass是什么?V1和V2版本及其差异
AWS IoT Greengrass Greengrass主要是用于边缘计算或者机器学习有关,对于详细了解请阅读结尾处的官方文档,文档内容也较为丰富. 目录 AWS IoT Greengrass ...
- jenkins Windows下自动化部署.netcore
(1) 安装java-sdk (Jdk5-11)不用配置环境变量 https://www.oracle.com/java/technologies/javase/javase-jdk8-downloa ...
- 人工智能"眼睛"——摄像头
摄像头机器视觉人工智能的"眼睛",其重要性在嵌入式领域不言而喻.但是如何理解和使用摄像头却是一个非常棘手的问题.本文主要针对调试摄像头过程中遇到的问题,对摄像头的基本原理及概述进行 ...
- LR_添加系统资源监控失败
1.服务开启情况:RPC.Rmote Resgistry.Network DDE.Server.Workstation.Network connection以上服务是否已开启 2.是否开了防火墙,如有 ...