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\);
标签:include,int,LL,atk,牛客,取整,2023,集训营 From: https://www.cnblogs.com/J-12045/p/17080752.html