- 编程
龟兔赛跑
- 2025-2-9 16:34:32 @
题目大纲:
乌龟和兔子赛跑,兔子因为骄傲自大败给了乌龟。他们再举行了一场赛跑,要求谁赢了。
输入格式:
第一行两个整数r和t,表示兔子的速度和乌龟的速度。
第二行两个整数n和k,表示赛道的长度和兔子休息的时间。(确保乌龟坚持不懈,兔子休息了)
输出格式:
一行字符串,如果乌龟赢了输出“Tortoise”,兔子赢了输出“Rabbit”,同时到达输出“Both”。
样例输入1:
100 16
800 30
样例输出1:
Rabbit
样例1解释:
兔子跑800米用时8分钟,加上休息的30分钟,一共38分钟,期间乌龟一共跑了38*16=608米,所以兔子赢了。
数据范围:
确保m不为0,1<r、t、n、m<10000
2 条评论
-
王嘉澔 LV 7 @ 2025-2-10 20:41:42
```#include<bits/stdc++.h> using namespace std; double a,b; int main() { cin>>a>>b; int c,d; cin>>c>>d; int e=c-d*b; if(c/a>e/b){ cout<<"Turtle"; }else if(c/a<e/b){ cout<<"Rabbit"; }else{ cout<<"Both"; } return 0; }
👍 1 -
2025-2-10 14:53:39@
代码如下
#include <bits/stdc++.h> using namespace std; int main() { int r, t; cin >> r >> t; int n, k; cin >> n >> k; double rt = (double)n / r + k; double tt = (double)n / t; if (rt < tt) { cout << "Rabbit" << endl; } else if (rt > tt) { cout << "Tortoise" << endl; } else { cout << "Both" << endl; } return 0; }
👍 1
- 1