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> ...
随机推荐
- mpvue 踩坑之src数据绑定出错
原文链接:https://blog.csdn.net/weixin_38984353/article/details/80847288 src实现数据绑定稍不留神就不成功.假定value.src是绑定 ...
- Android Visibility控件显示和隐藏
Android控件显示和隐藏 visibility 可见(visible) XML文件:android:visibility="visible" Java代码:view.setVi ...
- go 锁和sync包
一.什么是锁? sync.Mutex 是一个互斥锁,它的作用是守护在临界区入口来确保同一时间只能有一个线程进入临界区 在 sync 包中还有一个 RWMutex 锁:他能通过 RLock() 来允许同 ...
- Array(数组)对象-->shift() 方法
1.定义和用法 shift() 方法用于把数组的第一个元素从其中删除,并返回第一个元素的值. 语法: array.shift() 注意: 此方法改变数组的长度! 举例: var arr = [1,2, ...
- matplotlib Transform
2020-04-09 15:09:02 -- Edit by yangray Transform 类是TransformNode的子类,它是所有执行变换的TransformNode的实例的基类.所有非 ...
- java解惑之常常忘记的事
java解惑之常常忘记的事 2012-10-17 18:38:57| 分类: JAVA | 标签:基础知识 软件开发 |举报|字号 订阅 针对刚接触java的菜鸟来说,java基础知识 ...
- 一个不错的intellj 相关的博客
http://my.oschina.net/lujianing/blog?catalog=3300430
- Git应用详解第八讲:Git标签、别名与Git gc
前言 前情提要:Git应用详解第七讲:Git refspec与远程分支的重要操作 这一节主要介绍Git标签.别名与Git的垃圾回收机制. 一.Git标签(tag) 1.标签的实质 标签与分支十分相似, ...
- JSON Extractor(JSON提取器)
JSON提取器 Variable names(名称):提取器的名称Apply to(应用范围):Main sample and sub-samples:应用于主sample及子sampleMain s ...
- Wireshark的两种过滤器与BPF过滤规则
Wirshark使用的关键就在于过滤出想要的数据包,下面介绍怎么过滤. 抓包过滤器 Wirshark有两种过滤器,一个是抓包过滤器,一个是显示过滤器,他们之间的区别在于抓包过滤器只抓取你设置的规则,同 ...