跳到正文

题解

题解:P12170 [蓝桥杯 2025 省 Python B] 攻击次数

easy42约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年4月14日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 1 分钟
获赞
4
题目
P12170

版本

  1. v1当前

本题考查分支语句。

在这里,使用 ansans 记录回合数,nn 记录血量。

第一个英雄恒定,直接减去 55 即可。

第二个英雄奇数减 1515,偶数减 22。

C++
if(ans%2==1) n-=15;
else n-=2;

第三个英雄当回合数除以 33 的余数为 11 时攻击 22 的血量;当回合数除以 33 的余数为 22 时攻击 1010 的血量;当回合数除以 33 的余数为 00 时攻击 77 的血量。

C++
if(ans%3==1) n-=2;
else if(ans%3==2) n-=10;
else n-=7;

完整代码:

C++
#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;
}
原文