本题考查分支语句。
在这里,使用 记录回合数, 记录血量。
第一个英雄恒定,直接减去 即可。
第二个英雄奇数减 ,偶数减 。
if(ans%2==1) n-=15;
else n-=2;第三个英雄当回合数除以 的余数为 时攻击 的血量;当回合数除以 的余数为 时攻击 的血量;当回合数除以 的余数为 时攻击 的血量。
if(ans%3==1) n-=2;
else if(ans%3==2) n-=10;
else n-=7;完整代码:
#include<bits/stdc++.h>
using namespace std;
int ans=0;
int main(){
int n=2025;
while(1){
ans++;
n-=5;
if(ans%2==1) n-=15;
else n-=2;
if(ans%3==1) n-=2;
else if(ans%3==2) n-=10;
else n-=7;
if(n<=0) cout<<ans,exit(0);
}
return 0;
}