欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

蓝桥题目:B-24、龟兔赛跑预测

程序员文章站 2022-06-12 20:55:04
...

蓝桥题目:B-24、龟兔赛跑预测

#include <iostream>
#define l1 v1 * i1
#define l2 v2 * i2

using namespace std;

int main(){
	int v1, v2, t, s, l;
	cin >> v1 >> v2 >> t >> s >> l;
//	v1 = 10;
//	v2 = 3;
//	t = 20;
//	s = 15;
//	l = 3450;
//	cout << v1 <<" "<< v2 <<" "<< t <<" "<< s <<" "<< l <<endl; 
	
	int flag = 0, i1 = 1, i2 = 1;
	
	while(l1 < l && l2 < l){

//		cout << "第" << i2 << "秒:" << "i1:" << i1 << "; i2:"<< i2 << "; flag:"<< flag << endl;
//		cout << "	兔子跑了"<<v1*i1<<"	 乌龟跑了"<<v2*i2<<endl;

		if(l1 - l2 >= t && flag <= 0) flag = s;
		if(flag > 0) i1--;
		flag--;
		i1++;
		i2++;
	}
	
//	cout << "循环完成" << endl;
//	cout << "第" << i2 << "秒:" << "i1:" << i1 << "; i2:"<< i2 << "; flag:"<< flag << endl;
	
	if(l1 > l2){
		cout << "R" << endl << i2;
	}else if(l1 < l2){
		cout << "T" << endl << i2;
	}else if(l1 == l2){
		cout << "D" << endl << i2;
	}
	
	return 0;
}