[OpenJudge2404]Ride to Office

描述
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

题意:
MZone中除了Weiwei的人都以固定的速度骑自行车到办公室,Weiwei则总是跟着别人。Weiwei在0时刻到达MZone的大门,他会寻找一个人跟随。如果有人在0时刻出发,他就会跟随那个人,否则他会等着,直到有人出发。在路上,如果一个更快的人超过了魏伟,他将跟随那个更快的人。
MZone到办公室的距离为4.5km。

给出n个人的速度v(km/h)和出发时间t(s),求Weiwei到达办公室的时间(s)。


题解:
只需算出出发时间t>=0的陪伴人到达终点的时间就可以了
weiwei一定会和出发时间t>=0并且最先到达的陪伴人同时到达

而对于出发时间t<0的陪伴人, weiwei肯定追不上

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
const double INF=1e40;
int n;
double v, t, T;

int main() {
	while( ~scanf( "%d", &n ) ) {
		if( !n ) break;
		T=INF;
		for( int i=1; i<=n; i++ ) {
			scanf( "%lf%lf", &v, &t );
			if( t>=0 ) {
				t=t+45*360/v;
				T=min( T, t );
			}
		}
		printf( "%d\n", (int)(T+0.99) );
		}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值