蓝桥杯 基础练习 龟兔赛跑预测 (vip)

版权声明:(整理不易,如本文对您有益,请为我点赞吧!)本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/Qi2456/article/details/88100552

 基础练习 龟兔赛跑预测

代码

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int v1,v2,t,s,l;
    cin>>v1>>v2>>t>>s>>l;
    int num=0,s1=0,s2=0;
    while(1)
    {

        if(s1>=l&&s2>=l)
        {
            cout<<"D"<<endl;
            cout<<num;
            break;
        }
        else if(s1>=l)
        {
            cout<<"R"<<endl;
            cout<<num;
            break;
        }
        else if(s2>=l)
        {
            cout<<"T"<<endl;
            cout<<num;
            break;
        }
        if(s1-s2>=t)
        {
            for(int i=0;i<s;i++)
            {
                num++;
                s2+=v2;
                if(s2>=l)
                {
                    cout<<"T"<<endl;
                    cout<<num;
                    exit(0);
                }
            }

        }
        else
        {
            num++;
        s1+=v1;
        s2+=v2;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Qi2456/article/details/88100552
今日推荐