FOJ 1889 龟兔赛跑
程序员文章站
2022-06-07 23:37:41
...
一,问题描述
二,问题分析
思路很简单,只需要根据题意比较龟兔的路程即可,兔子:(总时间 - 睡觉时间)*速度 乌龟:总时间 * 速度
三,代码解答
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
struct Game
{
int allTime; //比赛时间
int sleepTime; //兔子睡觉时间
int rspeed; //兔子时速
int tspeed; //乌龟时速
};
int main() {
int num; //比赛组数
cin >> num;
vector<Game> games(num);
vector<int> out(num);
for (int i = 0; i < num; i++) {
cin >> games[i].allTime >> games[i].sleepTime >> games[i].rspeed >> games[i].tspeed;
if ((games[i].allTime - games[i].sleepTime) * games[i].rspeed > games[i].allTime*games[i].tspeed) { //兔子胜
out[i] = 0;
}
else if ((games[i].allTime - games[i].sleepTime) * games[i].rspeed < games[i].allTime * games[i].tspeed) //乌龟胜
{
out[i] = 1;
}
else
{
out[i] = -1;
}
}
for (int i = 0; i < num; i++) {
cout << out[i] << endl;
}
return 0;
}