电车痴汉
-
描述
-
Many staff of are living in a place called MZone, far from their office( 4.5 km ). Due to the bad traffic, many staff choose to ride a bike.
We may assume that all the people except "Weiwei" ride from home to office at a fixed speed. Weiwei is a people with a different riding habit – he always tries to follow another rider to avoid riding alone. When Weiwei gets to the gate of MZone, he will look for someone who is setting off to the Office. If he finds someone, he will follow that rider, or if not, he will wait for someone to follow. On the way from his home to office, at any time if a faster student surpassed Weiwei, he will leave the rider he is following and speed up to follow the faster one.
We assume the time that Weiwei gets to the gate of MZone is zero. Given the set off time and speed of the other people, your task is to give the time when Weiwei arrives at his office.
输入
-
There are several test cases. The first line of each case is N (1 <= N <= 10000) representing the number of riders (excluding Weiwei). N = 0 ends the input. The following N lines are information of N different riders, in such format:
Vi [TAB] Ti
Vi is a positive integer <= 40, indicating the speed of the i-th rider (kph, kilometers per hour). Ti is the set off time of the i-th rider, which is an integer and counted in seconds. In any case it is assured that there always exists a nonnegative Ti.
输出
- Output one line for each case: the arrival time of Weiwei. Round up (ceiling) the value when dealing with a fraction. 样例输入
-
4 20 0 25 -155 27 190 30 240 2 21 0 22 34 0
样例输出
-
780 771
对于n个骑行者,你,电车痴汉,从时刻0开始出发,谁快就跟着谁。
恍惚间,你会发现你最后一个尾随的人到达的时间就是你最快的时间,因为用时最少那么他一定会追上你,你一定会最后跟着他走,他到达的时间也就是你达到的最少时间了
t<0不用考虑,人家早跑了你尾行谁去?
#include<cmath>
#include<cstdio>
#include<iostream>
#define N 10010
using namespace std;
const int inf=1<<30;
int v,t;
int n,ans;
int main(){
while (scanf("%d",&n) && n)
{
ans=inf;
for (int i=1;i<=n;i++)
{
scanf("%d%d",&v,&t);
if (t<0) continue;
int time=(int) ceil(4.5/v * 3600) +t;
ans=min(ans,time);
}
printf("%d\n",ans);
}
return 0;
}