首页 > 其他 > 详细

CodeForces 1102C-简单的思维题

时间:2019-01-20 13:17:14      阅读:210      评论:0      收藏:0      [点我收藏+]

题目链接http://codeforces.com/problemset/problem/1102/C

 

C. Doors Breaking and Repairing
time limit per test                                                                                                                                                                                                                                                             
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

 

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?

 

Input

The first line of the input contains three integers nn, xx and yy (1n1001≤n≤100, 1x,y1051≤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 (1ai1051≤ai≤105), where aiai is the initial durability of the ii-th door.

 

Output

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.

 

Examples
input
Copy
6 3 2
2 3 1 3 4 2
output                          
Copy
6
input
Copy
5 3 3
1 2 4 2 3
output
Copy
2
input
Copy
5 5 6
1 2 6 10 3
output
Copy
2

 

Note

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;    
} 

(第一次博客,多多见谅)

 

CodeForces 1102C-简单的思维题

原文:https://www.cnblogs.com/tombraider-shadow/p/10294434.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!