• 蓝桥杯 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;	
    				}
    			}
    		}
    	}
    }


  • 相关阅读:
    【BJOI2018】求和
    【洛谷P1613】跑路
    【NOI2001】食物链
    【NOI2002】银河英雄传说
    【POJ1456】Supermarket
    【NOIP2013】货车运输
    【CH#56C】异象石
    【POJ3417】Network
    【APIO2010】巡逻
    【CH6201】走廊泼水节
  • 原文地址:https://www.cnblogs.com/yxwkf/p/5256956.html
Copyright © 2020-2023  润新知