【题解】CF1154D:Walking Robot

原题传送门
贪心模拟
分类讨论

  • 如果蓄电池没电了,那么肯定走干电池,如果走到一条1线段,蓄电池电量可以+1
  • 如果蓄电池还有电,那么如果干电池没电,或者下一条线段为0,又或者蓄电池目前满电,走蓄电池,否则才走干电池

Code:

#include <bits/stdc++.h>
#define maxn 200010
using namespace std;
int n, a, b, c;

inline int read(){
	int s = 0, w = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') w = -1;
	for (; isdigit(c); c = getchar()) s = (s << 1) + (s << 3) + (c ^ 48);
	return s * w;
}

int main(){
	n = read(), a = read(), c = b = read();
	int ans = 1;
	for (; ans <= n; ++ans){
		int x = read();
		if (!c){
			if (x) ++c;
			--a;
		} else{
			if (c == b || !x || !a) --c;
			else{
				--a;
				if (x) ++c;
			}
		}
		if (!a && !c || ans == n) break;
	//	printf("%d %d\n", a, c);
	}
	printf("%d\n", ans);
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值