P8534 题解

· · 题解

思路

本题考查分支结构的基本应用。

首先判断 x\ge3x\ge5(关卡),然后依次判断 s\ge10^7s\ge2\times10^7s\ge4\times10^7s\ge6\times10^7(分数),统计判断成立次数,最后加上最开始 2 个残机即为答案。

注意事项

AC CODE

#include<bits/stdc++.h>
using namespace std;
#define int long long
int read(){int x=0;char f=1,ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();return x*f;}
void solve(){
    int x=read(),s=read();
    int cnt=2; // 初始的 2 个残机

    // 判断是否通过关卡
    if(x>=3)
        ++cnt;
    if(x>=5)
        ++cnt;

    // 判断是否达到分数
    if(s>=10000000)
        ++cnt;
    if(s>=20000000)
        ++cnt;
    if(s>=40000000)
        ++cnt;
    if(s>=60000000)
        ++cnt;

    printf("%lld\n",cnt);
    return;
}
signed main(){
    int T=read();
    while(T--)
        solve();
    return 0;
}