1815. 【Easy】一丝一丝一丝!大残大残大残!

#include <bits/stdc++.h> using namespace std; double PI = 3.1415926; int main(void) { //计算敌人血量 int shield; cin >> shield; int HP=0; switch (shield) { case 1:HP = 150; break; case 2:HP = 175; break; case 3:HP = 200; break; case 4:HP = 225; break; default: break; } //选择武器 int weapon; cin >> weapon; int DPS=0; switch (weapon) { case 1:DPS = 14; break; case 2:DPS = 18; break; case 3:DPS = 11; break; case 4:DPS = 45; break; default: break; } int AmmoCount = 0; while (HP > 0)//计算多少发击杀 { HP -= DPS; AmmoCount++; } //因为算出来的是击杀所需,所以应该加回来一次 HP += DPS; AmmoCount--; cout << AmmoCount << " " << HP << endl; return 0; }

or

#include <bits/stdc++.h> using namespace std; #define sc(x) scanf("%lld", &x) using ll = long long; ll hp[] = {0, 150, 175, 200, 225}, dmg[] = {0, 14, 18, 11, 45}; ll si, wi, cnt, rest; signed main() { sc(si), sc(wi); cnt = (hp[si] - 1) / dmg[wi], rest = hp[si] - dmg[wi] * cnt; printf("%lld %lld", cnt, rest); return 0; }