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 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 yyis 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 (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.

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

6 3 2
2 3 1 3 4 2

Output

6

Input

5 3 3
1 2 4 2 3

Output

2

Input

5 5 6
1 2 6 10 3

Output

2

Note

Clarifications about the optimal strategy will be ignored.

题目链接:https://vjudge.net/problem/CodeForces-1102C

题意:给你一个含有N个数的数组,每一个元素代表一个门的当前防御值

每一次你可以对门攻击x个点数,而一个神仙可以对门进行y个点数的防御值提升。

当一次你对门的攻击使这个门的防御值小于等于0的时候,这个门就坏掉了,神仙也没法修复了。

问:当你和神仙都采取最优的策略的时候,你最多可以砸坏几个门?

思路:

分2种情况

1: X>Y ,这样的话,每一个门你都可以给砸坏。(不用解释吧)

2:当x<=y,这样你的最优策略就是每一次去砸那些当前防御值比你的攻击力x值小的门,一次就可以给砸坏,

而神仙的最优策略使去提升那些当前防御值比你的攻击力x值小的门,一次来减少你的数量。

通过样例我们可以推出公式,如果初始化的时候有cnt个门当前防御值比你的攻击力x值小,那么答案就是(ans+1)/2

我的AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), ‘\0‘, sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n,x,y;
int a[maxn];
int main()
{
    gbtb;
    cin>>n>>x>>y;
    repd(i,1,n)
    {
        cin>>a[i];
    }
    if(x<=y)
    {
        int ans=0;
        repd(i,1,n)
        {
            if(a[i]<=x)
            {
                ans++;
            }
        }
        ans=(ans+1)/2;
        cout<<ans<<endl;
    }else
    {
        cout<<n<<endl;
    }
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ‘ ‘ || ch == ‘\n‘);
    if (ch == ‘-‘) {
        *p = -(getchar() - ‘0‘);
        while ((ch = getchar()) >= ‘0‘ && ch <= ‘9‘) {
            *p = *p * 10 - ch + ‘0‘;
        }
    }
    else {
        *p = ch - ‘0‘;
        while ((ch = getchar()) >= ‘0‘ && ch <= ‘9‘) {
            *p = *p * 10 + ch - ‘0‘;
        }
    }
}

MY BLOG:
https://www.cnblogs.com/qieqiemin/

原文地址:https://www.cnblogs.com/qieqiemin/p/10253192.html

时间: 2024-11-09 05:17:20

Doors Breaking and Repairing CodeForces - 1102C (思维)的相关文章

Queue CodeForces - 353D (思维dp)

https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为位置$i$处的$F$复位所花费时间, 有 $dp[i] = max(dp[i-1]+1,cnt_i)$, $cnt_i$为前$i$位$M$的个数 $dp$最大值即为答案 #include <iostream> #include <algorithm> #include <cstd

CodeForces 1131B(思维题)

You still have partial information about the score during the historic football match. You are given a set of pairs (ai,bi)(ai,bi), indicating that at some point during the match the score was "aiai: bibi". It is known that if the current score

CodeForces - 417B (思维题)

Crash Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know th

CodeForces - 417A(思维题)

Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.

BACK DOORS AND FRONT DOORS BREAKING THE UNBREAKABLE SYSTEM

Governments are demanding backdoor access to encrypted data - particularly on mobile devices and in the cloud - as strong encryption becomes commonplace. Governments fear going dark with encryption hindering criminal and national security investigati

codeforces 940E 思维,dp

E. Cashback 题意: 给出常数 c ,定义长度为 n 的序列的价值为:舍去前 (floor)( n/c ) 个最小的数,余下的数的和. n 个数的序列,要你把它们分隔成多个序列,顺序不能改变.最后的答案为 所有序列的价值的和,求最小的答案. tags: 我们可以推测出:最后最优的答案,序列长度一定是 c 或 1 .因为如果有 k*c 长度的序列,我们把它分成 k 个长度为 c 的最优: 如果有 k*c+m 的长度序列,那么最后分出 m 个长度为 1 的序列也是更优. 所以就直接 dp

Codeforces 1093C (思维+贪心)

题面 传送门 题目大意: 有一个长n(n为偶数)的序列a 已知a满足 \(a_1≤a_2≤?≤a_n\) 给出一个长度为\(\frac{n}{2}\) 的序列b,定义\(b_i=a_i+a_{n-i+1}\) 求出序列a (输出任意一种答案即可) 分析 为了保证序列不下降,我们采用贪心的思想,先假设\(a_i=a_{i-1}\),这样给后面的数留有的余地更大 然后计算出\(a_{n-i+1}=b_i-a_i\),如果\(a_{n-i+1}>a_{n-i+1+1}\),即不满足不下降的条件,则进行

Codeforces 1110C (思维+数论)

题面 传送门 分析 这种数据范围比较大的题最好的方法是先暴力打表找规律 通过打表,可以发现规律如下: 定义\(x=2^{log_2a+1}\) (注意,cf官方题解这里写错了,官方题解中定义\(x=2^{log_2a}\)是有问题的 (1) 若\(a \neq 2^x-1\) ? 则当\(b=(2^x-1)\) xor a时a xor b=b=\(2^x-1\) ,a and b=0 ? gcd(a xor b,a and b)=\(2^x-1\)有最大值 ? (异或的性质,若a xor c =

Andrew and Taxi CodeForces - 1100E (思维,拓扑)

大意: 给定有向图, 每条边有一个权值, 假设你有$x$个控制器, 那么可以将所有权值不超过$x$的边翻转, 求最少的控制器数, 使得翻转后图无环 先二分转为判定问题. 每次check删除能动的边, 若剩余图有环显然不成立, 否则将剩余的图拓排一下, 再把能动的边按拓排的方向即可保证无环. #include <iostream> #include <algorithm> #include <math.h> #include <cstdio> #include