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 @   Keith-  阅读(31)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示