Codeforce 1102 C. Doors Breaking and Repairing
Descirbe
You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.
There are n doors, the i-th door initially has durability equal to ai.
During your move you can try to break one of the doors. If you choose door i and its current durability is bi then you reduce its durability to max(0,bi−x) (the value x is given).
During Slavik’s move he tries to repair one of the doors. If he chooses door i and its current durability is bi then he increases its durability to bi+y (the value y is given). Slavik cannot repair doors with current durability equal to 0.
The game lasts 10100 turns. If some player cannot make his move then he has to skip it.
Your goal is to maximize the number of doors with durability equal to 0 at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally?
Input
The first line of the input contains three integers n, x and y (1≤n≤100, 1≤x,y≤105) — the number of doors, value x and value y, respectively.
The second line of the input contains n integers a1,a2,…,an (1≤ai≤105), where ai is the initial durability of the i-th door.
Output
Print one integer — the number of doors with durability equal to 0 at the end of the game, if you and Slavik both play optimally.
Examples
inputCopy
6 3 2
2 3 1 3 4 2
outputCopy
6
inputCopy
5 3 3
1 2 4 2 3
outputCopy
2
inputCopy
5 5 6
1 2 6 10 3
outputCopy
2
Note
Clarifications about the optimal strategy will be ignored.
题意大概是两个人玩游戏一个警察,一个坏蛋,一个人破门,一个人补门,警察像破开尽可能多的门,坏蛋想让警察破开门尽可能少,这时候就疑惑了,这到底是让我们求最大值,还是最小值?在这里我们看到,两个人的意愿也改变不了必然的结果,就拿这一组数据
6 3 2
2 3 1 3 4 2
6扇门,警察破门掉 3个耐久,坏蛋修门增加2个耐久,警察与坏蛋轮流操作,警察为破开更多的们,会选择第一次就能破开,或者说最小耐久值的门,坏蛋也是这样想的,他会修补那些一次就被警察破门的门,前提是坏蛋增加耐久大于警察破门,不然以题目这样的数据,一直撞迟早也是撞开的,当坏蛋修补增加的耐久大于警察撞门耐久时,便有了以下操作
5 5 6
1 2 6 10 3
警察第一次撞门 1
坏蛋第一次修门 2
警察第二次撞门 3
再往后警察一次撞不开一扇门,而坏蛋使门的耐久度越来越高,这就得出了必然的结果。
下面是AC code
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int x,y,n,a[10000],s;
while(cin>>n>>x>>y)
{
s=0;
for(int i=1;i<=n;i++)
cin>>a[i];
if(x>y)
{
cout<<n<<endl;
}
else if(x<=y)
{
sort(a+1,a+1+n);
int w=1;
for(int i=1;i<=n;i++)
{
if(a[i]<=x)
s++;
}
if(s%2==1) s=s/2+1;
else s=s/2;
cout<<s<<endl;
}
}
}
Codeforce 1102 C. Doors Breaking and Repairing的更多相关文章
- Doors Breaking and Repairing
题目链接:Doors Breaking and Repairing 题目大意:有n个门,先手攻击力为x(摧毁),后手恢复力为y(恢复),输入每个门的初始“生命值”,当把门的生命值攻为0时,就无法恢复了 ...
- Doors Breaking and Repairing CodeForces - 1102C (思维)
You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consi ...
- Codeforces Round #531 (Div. 3) C. Doors Breaking and Repairing (博弈)
题意:有\(n\)扇门,你每次可以攻击某个门,使其hp减少\(x\)(\(\le 0\)后就不可修复了),之后警察会修复某个门,使其hp增加\(y\),问你最多可以破坏多少扇门? 题解:首先如果\(x ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Reinvent the Wheel Often
Reinvent the Wheel Often Jason P. Sage Just use something that exists-it's silly to reinvent the whe ...
- How can I protect derived classes from breaking when I change the internal parts of the base class?
How can I protect derived classes from breaking when I change the internal parts of the base class? ...
- poj 1102.LC-Display 解题报告
题目链接:http://poj.org/problem?id=1102 题目意思:就是根据给出的格式 s 和 数字 n,输出数值 n 的 LCD 显示.数值 n 的每个数字要占据 s + 2 列 和 ...
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- HDU 1102 最小生成树裸题,kruskal,prim
1.HDU 1102 Constructing Roads 最小生成树 2.总结: 题意:修路,裸题 (1)kruskal //kruskal #include<iostream> ...
随机推荐
- 微信小程序中使用template
当我们的项目需要多次使用同一个布局和样式的时候,我们就可以考虑使用template(模块)来减少冗余的代码. 使用方法: 1. 新建一个template文件夹存放通用模板: 2. 在文件夹汇里面新建一 ...
- SQL基础系列(2)-内置函数--转载w3school
1. 日期函数 Mssql: SELECT GETDATE() 返回当前日期和时间 SELECT DATEPART(yyyy,OrderDate) AS OrderYear, DATEPART( ...
- IntelliJ IDEA 在方法大括号中{}点击回车多出一个},如何取消
在 File - settings - Editor - General- Smart Keys - Enter 去掉 Insert pair '}' 的对勾就可以了
- 数据结构和算法(Golang实现)(17)常见数据结构-树
树 树是一种比较高级的基础数据结构,由n个有限节点组成的具有层次关系的集合. 树的定义: 有节点间的层次关系,分为父节点和子节点. 有唯一一个根节点,该根节点没有父节点. 除了根节点,每个节点有且只有 ...
- XML布局界面
Android推荐使用XML布局文件来定义用户界面,而不是使用Java代码来开发用户界面,因此基础所有组件都提供了两种方式来控制组件的行为:1.在XML布局文件中通过XML属性进行控制:2.在Java ...
- 小说免费看!python爬虫框架scrapy 爬取纵横网
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 风,又奈何 PS:如有需要Python学习资料的小伙伴可以加点击下方 ...
- python基础:如何使用python pandas将DataFrame转换为dict
之前在知乎上看到有网友提问,如何将DataFrame转换为dict,专门研究了一下,pandas在0.21.0版本中是提供了这个方法的.下面一起学习一下,通过调用help方法,该方法只需传入一个参数, ...
- frp内网穿透学习
前言 因为自己在内网,但是目标站在外网,这时候可以通过内网穿透工具,将接收到的请求转发到内网,实现在内网的msf可以控制外网的靶机. 也看了一些Ngrok,花生壳的,发现Ngrok.cc这个看文章说有 ...
- 从零开始学AB测试:躲坑篇
AB测试的原理很简单,只用到了最简单的统计假设检验,但表面的简单通常都隐藏着陷阱,这一点没有经过实践的摸爬滚打是不容易看到的,今天我就把前人已经踩过的坑,一共15个,给大家分享一下.在分享之前,大家脑 ...
- 使用dynamic和MEF实现轻量级的AOP组件 (3)
转摘 https://www.cnblogs.com/niceWk/archive/2010/07/22/1783068.html 水到渠成 在上一篇的<偷梁换柱>中,介绍了Weavabl ...