VIP test questions basic practice tortoise and hare race prediction (C language)

Resource limit

Time limit: 1.0s Memory limit: 512.0MB

Problem Description

  It is said that there are all kinds of rabbits and tortoises in the world, but research has found that all rabbits and tortoises have a common characteristic-like racing. As a result, tortoise and hare races are constantly taking place in all corners of the world. Xiaohua is very interested in this, so he decides to study the races of different rabbits and tortoises. He found that although rabbits run faster than tortoises, they have a well-known problem-proud and lazy, so in a game with tortoises, once the rabbits find themselves ahead of t meters or more after any second, they will stop. Rest for s seconds. For different rabbits, the values ​​of t and s are different, but all tortoises are the same-they never stop when they reach the end.
  However, some games are quite long and the whole viewing process will take a lot of time. Xiaohua found that as long as the data of the rabbit and the tortoise are recorded after each game starts-the rabbit's speed v1 (which means that the rabbit can run v1 meters per second), the tortoise's The speed v2, and the t and s values ​​corresponding to the rabbit, and the length of the track l-can predict the outcome of the race. But Xiaohua is lazy and doesn't want to use manual calculations to guess the result of the game, so he found you-a talented student in the Department of Computer Science of Tsinghua University-for help, please write a program, for the input data v1 of a game, v2, t, s, l, predict the outcome of the game.

Input format

  The input is only one line and contains five positive integers v1, v2, t, s, l separated by spaces, where (v1, v2<=100; t<=300; s<=10;l<=10000 and v1 , common multiple of v2)

Output format

  The output consists of two lines. The first line outputs the result of the competition-a capital letter "T" or "R" or "D", which means that the tortoise wins, the rabbit wins, or both reach the end at the same time.
  The second line outputs a positive integer, which represents the time (in seconds) it takes for the winner (or both at the same time) to reach the end point.

Sample input

10 5 5 2 20

Sample output

D
4

Sample input

10 5 5 1 20

Sample output

R
3

Sample input

10 5 5 3 20

Sample output

T
4

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int sum1=0,sum2=0;
	int v1,v2,t,s,l;
	scanf("%d%d%d%d%d",&v1,&v2,&t,&s,&l);
	int t1=0,i;
	
	while(sum1<l&&sum2<l)
	{
		t1++;
		sum1+=v1;
		sum2+=v2;
		if(sum1>=l||sum2>=l)
		break;
		if(sum1-sum2>=t)
		{
			for(i=1;i<=s;i++)
			{
				sum2+=v2;
				t1++;
				if(sum2>=l)
			    break;
			}
			
		}
		
	}
	if(sum1>sum2)
	printf("R\n");
	else if(sum1<sum2)
	printf("T\n");
	else
	printf("D\n");
	
	printf("%d",t1);
	return 0;
 } 

80 minutes in the first pass. Because the for loop is useless, it is written directly as sum+=v2*s; t1+=s;. So a few test data have not passed. Sure enough to do the questions carefully

Guess you like

Origin blog.csdn.net/with_wine/article/details/115016860