【FOJ】Problem 1190 Ride to School

Problem 1190 Ride to School.

The meaning of problems

  • There is a lonely and empty student C, when his ride with someone if they can, to press speed peers who ride, no one would wait until someone so far. Willow on the road to the Yanyuan (4.5km) if someone more than they, C will be bounced to talk faster man.
    Arrival time at 0 C Willow
  • A plurality of sets of input data:
    The number of rider N (1 <= N <= 10000), N = input end 0
    Vi (km / H), of Ti (S), the speed of the rider number i, the number i rider departure time
  • Output:
    the arrival time of the C (rounded up)

Thinking

  • C always followed ride that fast = C is the fastest and riding side by side to reach the end of the C = time to reach the finish time of the first rider to reach the end of
  • C certainly not follow the riders in the negative moment of departure to reach the end together:
    if the fastest rider, C along with others certainly will not catch up with him. If this is not the fastest rider, C may exceed only when he followed than he first rider to reach the end.
  • Each rider calculates time they reach the end of the minimum arrival time C taken
    by the h = 4.5 / Vi, s = h × 3600, t_arrive = s + Ti ( = arrival time departure time when riding with +)
    obtained t_arrive = 4.5 / Vi × 3600 + Ti

notes

  • Improvement / trade-integer
#include<math.h>
ceil(double);
floor(double);
注意这两的返回值不是int类型的

Code

#include<cstdio>
#include<math.h>
using namespace std;

int main(){
	int n, v, t;
	double min_t, t_arrive;
	scanf("%d", &n);
	while(n!=0){
		min_t = 100000;
		for(int i=0; i<n; i++){
			scanf("%d%d", &v, &t);
			if(t<0)
				continue;
			t_arrive = 4.5/v*3600.0 + t;
			if(t_arrive<min_t)
				min_t = t_arrive;
		}
		printf("%d\n", (int)ceil(min_t));
		scanf("%d", &n);
	}
	return 0;
}
Published 28 original articles · won praise 0 · Views 314

Guess you like

Origin blog.csdn.net/qq_44531167/article/details/105349226