基础训练 龟兔赛跑预测
作者:互联网
/****************根据题目这里的时间一定是整数,且题目说了l一定是v1和v2的整数倍*************/
#include<iostream>
using namespace std;
int main(){
int v1, v2, t, s, l, s1=0, s2=0, sec=0, t1, t2, tag1=0, tag2=0;
cin>>v1>>v2>>t>>s>>l;
while(s1<l||s2<l){
if(s1-s2>=t){
for(int i=1; i<=s; i++){
sec++;
s2+=v2;
if(s2>=l&&tag2==0){
t2=sec; tag2=1;
}
}
}else{
sec+=1;
s1+=v1;
s2+=v2;
}
if(s1>=l&&tag1==0){
t1=sec; tag1=1;
}
if(s2>=l&&tag2==0){
t2=sec; tag2=1;
}
}
if(t1==t2) cout<<"D"<<endl<<t1<<endl;
else if(t1<t2) cout<<"R"<<endl<<t1<<endl;
else cout<<"T"<<endl<<t2<<endl;
return 0;
}
标签:赛跑,tag2,s1,龟兔,t2,v2,v1,基础训练,sec 来源: https://www.cnblogs.com/A-Little-Nut/p/10349236.html