Blue Bridge Cup questions basic exercises forecasting Tortoise and the Hare

Ideas: simulation, find the relevant constraints, then you can determine who should reach the end

For simulation title has not been very skilled, this question is that we as a measure of the distance, and then when one of the break to see what big, and then determine which wins, so if the distance between them is not greater than t, then the words that is, both are on the run, so then the two distances are updated, but if it is larger than the case, then do not run rabbit, tortoise will only update with the distance of time can!

#include<bits/stdc++.h>

using namespace std;

int v1, v2, t, s, l;

int main(){
	cin >> v1 >> v2 >> t >> s >> l;
	
	int l1 = 0, l2 = 0;
	int t1 = 0, t2 = 0;
	
	while (l1 != l && l2 != l) {
		if ((l1 - l2) >= t) {
			t2 += s;
			l2 =  v2 * t2;
		} 
		else {
			t1++;
			t2++;
			l1 = v1 * t1;
			l2 = v2 * t2;
		}
	} 
	if (l1 == l2) {
		cout << "D" << endl << t2;
	} else if (l1 > l2) {
		cout << "R" << endl << t2;
	}else {
		cout << "T" << endl << l/v2;
	}
	return 0;
} 

Published 177 original articles · won praise 6 · views 6386

Guess you like

Origin blog.csdn.net/qq_45585519/article/details/104671421