题目本身比较简单,但是所涉及到的小细节稍微多一些,但本意是模拟
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> using namespace std; typedef long long ll; int h , a , H , A; int n; void work() { ll ans = 0; // 当毛球的攻击力 <= 0 或者一刀一个毛球 if(A <= 0 || a >= H){ cout << -1 << endl; return; } else if(a == 0){ // 当自己攻击力为零时一个都杀不死 cout << 0 << endl; return; }else{ while(h > 0) { int t = H; while(t > 0) { if(h > 0)t = t - a; // 毛球被刀 else break; if(t > 0)h = h - A; // 如果毛球还活着你被刀 else break; } if(t <= 0 && h > 0)ans++; } cout << ans << endl; } } int main() { cin >> n; while(n --) { cin >> h >> a >> H >> A; work(); } return 0; }