标签:mat 假设 nbsp ast number init 简单的 reduce tom
题目链接:http://codeforces.com/problemset/problem/1102/C
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 nn doors, the ii-th door initially has durability equal to aiai.
During your move you can try to break one of the doors. If you choose door ii and its current durability is bibi then you reduce its durability to max(0,bi?x)max(0,bi?x) (the value xx is given).
During Slavik‘s move he tries to repair one of the doors. If he chooses door ii and its current durability is bibi then he increases its durability to bi+ybi+y (the value yy is given). Slavik cannot repair doors with current durability equal to 00.
The game lasts 1010010100 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 00 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?
The first line of the input contains three integers nn, xx and yy (1≤n≤1001≤n≤100, 1≤x,y≤1051≤x,y≤105) — the number of doors, value xx and value yy, respectively.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1051≤ai≤105), where aiai is the initial durability of the ii-th door.
Print one integer — the number of doors with durability equal to 00 at the end of the game, if you and Slavik both play optimally.
6 3 2
2 3 1 3 4 2
6
5 3 3
1 2 4 2 3
2
5 5 6
1 2 6 10 3
2
Clarifications about the optimal strategy will be ignored.
题目大意:这道题的题意认真读的话很简单,就是两个人做游戏。在两个人面前有n张门,每一个门的耐久度(durability)都已给出。两个人一个人破坏门(每次减少门的耐久度x)
另一个人是修门(每次增加门的耐久度y)两个人是回合制的,如果一个门的耐久度降到了0,则这个门将无法被修。
题目思维:题目中已给出回合数10的100次方,因此不可能都经历一边。这时候我们就要讨论x和y的关系,假设当x大于y的时候,每个回合要不门的耐久度下降,要不一个门被破坏
(因为x-y>0)这个时候所有的门都能够被破坏。(回合数足够多)
如果x<=y,我们只能去破坏一次可以破坏的门,假设我们没有去破坏一次可以破坏的(即你的回合后这个门的耐久度不是0)另一个人就要来修,这个门的耐久度要不上升,要不就不变
因此我们只能去破坏可以一次破坏的门,而当你破坏一个可以破坏的门后,另一个人会去修你原本可以一次破坏的门,这时你可以破坏的门数量就要下降。因此你破坏的门只能对半分。
附上AC代码:
#include<stdio.h> int main() { int n,x,y,a[110],ans; scanf("%d%d%d",&n,&x,&y); ans=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); if(a[i]<=x) ans++;//统计耐久度小于你的破坏值的门 } if(x>y) printf("%d\n",n);//第一种情况 if(x<=y) { if(ans%2==0) printf("%d\n",ans/2);//当可以门数是偶数 else printf("%d\n",ans/2+1);//可以破坏的是奇数,你是先手,肯定你的加一 } return 0; }
(第一次博客,多多见谅)
标签:mat 假设 nbsp ast number init 简单的 reduce tom
原文地址:https://www.cnblogs.com/tombraider-shadow/p/10294434.html