蓝桥杯 BASIC 24 龟兔赛跑预測(模拟)

【思路】:模拟。注意一个是在兔子歇息的时间乌龟可能到达了。刚開始没考虑WA80%。

【AC代码】:

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int v1 = 0, v2 = 0, t = 0, s = 0, l = 0;
	int len_t = 0, len_r = 0, cnt = 0, i = 0;
	cin >> v1 >> v2 >> t >> s >> l;
	while (true)
	{
		cnt++;
		len_r += v1;
		len_t += v2;
		if (len_r == len_t && len_t == l)
		{
			cout << "D" << endl << cnt;
			return 0;	
		}
		else if (len_t == l)		
		{
			cout << "T" << endl << cnt;
			return 0;	
		}
		else if (len_r == l)		
		{
			cout << "R" << endl << cnt;
			return 0;	
		}
		
		
		if (len_r - len_t >= t)
		{
			//cnt += s;
			//len_t += v2*s;
			for (i = 1; i <= s; i++)
			{
				cnt++;
				len_t += v2;
				if (len_r == len_t && len_t == l)
				{
					cout << "D" << endl << cnt;
					return 0;	
				}
				else if (len_t == l)		
				{
					cout << "T" << endl << cnt;
					return 0;	
				}
				else if (len_r == l)		
				{
					cout << "R" << endl << cnt;
					return 0;	
				}
			}
		}
	}
}


原文地址:https://www.cnblogs.com/yxwkf/p/5256956.html