基础训练 龟兔赛跑预测

龟兔赛跑预测

/****************根据题目这里的时间一定是整数,且题目说了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;
} 
posted @ 2019-02-02 21:35  A-Little-Nut  阅读(360)  评论(0编辑  收藏  举报