1227:Ride to Office

题目来源:http://ybt.ssoier.cn:8088/problem_show.php?pid=1227

1227:Ride to Office


时间限制: 1000 ms         内存限制: 65536 KB
提交数: 1503     通过数: 833 

【题目描述】

起点与终点相隔4500米。现Charley 需要从起点骑车到终点。但是,他有个习惯,沿途需要有人陪伴,即以相同的速度, 与另外一个人一起骑。而当他遇到以更快的速度骑车的人时,他会以相应的速度跟上这个更快的人。先给定所有与Charley 同路的人各自的速度与出发时间,问Charley 以这种方式跟人,骑完4500米需要多少时间。得出的结果若是小数,则向上取整。

【输入】

输入若干组数据,每组数据第一行n(1≤n≤10000),n为0,表示输入结束,接着输入n行数据,每行2个数据,表示速度v和出发时间t,如果t<0,表示陪伴人提早出发了。

【输出】

输出对应若干行数据,每行输出1个数,表示最快到达的时间。

【输入样例】

4
20 0
25 -155
27 190
30 240
2
21 0
22 34
0

【输出样例】

780
771

解析:
参考代码:
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cmath>
 5 using namespace std;
 6 int main()
 7 {
 8     int n;
 9     
10     while(cin>>n&&n!=0)
11     {
12         int t;
13         double time,v,ans=99999;
14         for(int i=1;i<=n;i++)
15         {
16             cin>>v>>t;
17             if(t<0) continue;
18             time=(4500/v*3.6);
19             time=ceil(time)+t;
20             if(ans>time) ans=time;
21         }
22         cout<<ans<<endl;
23     }
24 }

 

posted @ 2019-04-02 20:17  DarkValkyrie  阅读(824)  评论(0编辑  收藏  举报