The first question of the first game of Group B of the 2020 Blue Bridge Cup

running problem

Xiao Ming is going to do a running training.
At the beginning, Xiao Ming is full of physical strength, and the physical value is 10000. If Xiao Ming runs, he will consume 600 stamina per minute. If Xiao Ming rests, his stamina will increase by 300 per minute. The loss and increase of physical strength are uniform changes.
Xiao Ming plans to run for one minute, rest for one minute, run for another minute, and rest for another minute...and so on. If Xiao Ming's physical strength reaches 0 at a certain moment, he will stop exercising.
May I ask how long it will take for Xiao Ming to stop exercising. In order for the answer to be an integer, output the answer in seconds. Only fill in the number in the answer, do not fill in the unit.

#include <iostream>
using namespace std;

int main(){
    int guess = 10000;//初始体力值
    int run = 600/60;//每秒消耗的体力值
    int time =0;
    while(guess)
    {
        if(guess-600<0)
        {
            time = time*60+guess/run;
            break;
        }
        guess-=600;
        guess+=300;
        time+=2;
    }
    cout << time;
    return 0;
}

Answer

3880


 

Guess you like

Origin blog.csdn.net/m0_61105833/article/details/121595746