E 清楚姐姐打怪升级【2023牛客寒假算法基础集训营4】

E 清楚姐姐打怪升级

原题链接

代码

点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

#define X first
#define Y second

typedef long long LL;
const char nl = '\n';
const int N = 1e5+10;
int n,t,a;
LL h[N],v[N];	//防止爆int
void solve(){
	bool f = 0;
	LL atk = n;//每个都要攻击一次
	cin >> n >> t >> a;
	for(int i = 1; i <= n; i ++){
		cin >> h[i] >> v[i];
        v[i] *= t;	//每时间t攻击一次
		if(h[i] > a && v[i] >= a)f = 1;//不能一刀斩且恢复速度比掉血速度快	->无法击杀
		else if(h[i] > a)atk += ceil(1.0*(h[i]-a)/(a-v[i]));//如果不能一刀斩剩下还要砍几刀(向上取整)
	}
	if(f)cout << -1 << nl;
	else cout << (atk-1)*t+1 << nl;	//注意攻击间隔为t且从1开始
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);


	solve();
}

补充

向上取整\(a/b+a\)%\(b\)!=0;

posted @ 2023-01-31 20:56  Keith-  阅读(28)  评论(0编辑  收藏  举报