蓝桥杯 1476: [蓝桥杯][基础练习VIP]龟兔赛跑预测

基本思想:

题中提示了,按秒计数,这样不用像蚂蚁问题一样考虑半秒;

关键点:

直接按秒计算;

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector> 
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;



int main(){
	int v1, v2;
	int t, s, l;
	cin >> v1 >> v2 >> t >> s >> l;
	int m=0, n=0;//m兔子,n乌龟;
	int w=0;
	int cnt = 0;
	while (m<l&&n<l){
		cnt++;
		if (w != 0) {
			//兔子还在休息;
			n += v2;
			w--;
		}
		else {
			//兔子休息完了;
			if (m - n < t) {
				//如果没有领先;
				m += v1;
				n += v2;
				//两者继续前进;
			}
			else {
				//如果领先;
				n += v2;
				w = s-1;
			}
		}
	}
	if (m>=l&&n<l) {
		//兔子赢;
		cout << "R" << endl;
	}
	else if (m>=l&&n>=l) {
		cout << "D" << endl;
	}
	else {
		cout << "T" << endl;
	}
	cout << cnt << endl;
	return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/songlinxuan/p/12287106.html