Codeforces #531 (Div. 3) C. Doors Breaking and Repairing (思维博弈)

Doors Breaking and Repairing:

题目大意:(文末有原题)

给出n个整数,代表n个门的耐用度,玩家A每次会选择一个门,使这个门的耐用度减少x,玩家B每次会选择一个门,使这个门的耐用度增加y,A先操作,经过无限次操作后,判断会有几个门报废(耐磨度<=0);

思路:

首先如果每次破坏的大于修补的(x > y),无限次之后,一定会报废;

其次,因为破坏的小于等于修补的(x <= y),所以只有一次性直接使门报废,门才会报废,否则永远不会报废;

代码:

#include <iostream>
using namespace std;

int main() {
	int n, x, y, s = 0;
	cin >> n >> x >> y;
	int a[200];
	
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		
		if(a[i] <= x) {
			s++;
		}
	}
	
	if(x > y) {
		cout << n << endl;
	}else {    //因为你在破坏一扇门时,B可以修补那些 你还没有破坏的,并且 耐用度<x 的门,使你不能一次性使其报废 
		if(s % 2) {    //判断是否是奇数,因为A先操作,所以会多破坏一扇门
			cout << s / 2 + 1 << endl;
		}else {
			cout << s / 2 << endl;
		}
	}
	
	return 0;
}

原题:

题目:

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 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 bibi 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 ii and its current durability is bibi 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 10^100 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?

输入:

The first line of the input contains three integers n , x and y (1≤n≤1001≤n≤100 , 1≤x,y≤10^5 ) — the number of doors, value x and value y , respectively.

The second line of the input contains n integers a1,a2,…,an (1≤ai≤10^5 ), where aiai is the initial durability of the i -th door.

输出:

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.

样例:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值