【贪心】 noi openjudge 4.6 Ride to Office
2016-08-26 13:57
525 查看
2404:Ride to Office
总时间限制: 1000ms 内存限制: 65536kB描述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的地方,远离自己的办公室(4.5公里)。由于交通不畅,许多工作人员选择骑自行车。
我们可以假设,除了“维维”所有的人都从家里骑车到办公室以固定的速度。薇薇是一个人以不同的骑行习惯 - 他总是试图遵循另一个车手,以避免走单骑。当巍巍到达MZone的门,他会找人谁是关闭设置办公室。如果他发现有人,他将遵循的车手,如果没有,他会等待有人跟随。从他家到办公室的路上,如果在一个更快的学生超过了巍巍任何时候,他将离开他之后的车手,加快跟着快人。
我们假设维维到达MZone的栅极是零的时间。考虑到其他人的出征时间和速度,你的任务就是给时候,薇薇来到他的办公室
一开始我觉得既然维维走的速度是由陪伴人决定的,而陪伴人的速度已经决定,所以可以模拟过程,然而我WRONG
ANSWER了,然后我放弃了
于是换了一种方法,仔细想一想,其实只需算出出发时间>=0的陪伴人到达终点的时间就可以了,因为如果陪伴人出发时间>=0并且最先到达的话那么他肯定是追上来的,也就是说维维会跟上他,并且到达时间最短
而出发时间<0的陪伴人如果先到达,那么维维肯定追不上
如果后到达,维维不会跟着他
所以只用考虑>=0 的就行了
然后代码就变得简单了
代码:
#include<cstdio> int main() { double n,a,b,x,s; while(scanf("%lf",&n),n) { s=1000000; for(int i=1;i<=n;i++) { scanf("%lf%lf",&a,&b); if(b>=0){ x=4.5/a*3600+b; if(x<s) s=x;} } /* while(1) { for(int i=1;i<=n;i++) { p=b[i]; b[i]+=a[i]; if(b[i]>x&&p<=x) x=b[i],k=a[i]; } s++; if(x>=4500) { s--; x-=k; s+=int((4500-x)/k+0.99); break; } }*/原来模拟过程的代码,若有人模拟成功了,还请回复一下 printf("%d\n",int(s+0.99)); } }
相关文章推荐
- openjudge-noi-4.6-1455:An Easy Problem
- noi.openjudge 2469:电池的寿命 贪心
- NOI.OPENJUDGE 1.12.09的感想
- Openjudge-NOI题库-蛇形填充数组
- noi题库(noi.openjudge.cn) 1.8编程基础之多维数组T21——T25
- OpenJudge noi 7267 鸡蛋的硬度
- NOI OpenJudge 1159 Maze
- OpenJudge noi 2971抓住那头牛(POJ 3278)
- OpenJudge-Noi 2000 最长公共子上升序列
- How to Install Apache OpenOffice on RHEL/CentOS
- noi.openjudge 1.12.6
- noi.openjudge_P7627(鸡蛋的硬度)
- noi.openjudge——2971 抓住那头牛
- 【搜索】— 广搜队列 noi openjudge 2.5 Dungeon Master
- OpenJudge noi 1804小游戏(POJ1101)
- NOIOpenjudge 1.13--08特殊日历计算
- Ride to office
- Microsoft Office Open XML Document Formats Sent to ECMA
- NoiOpenJudge 2.5 城堡问题
- 一本通上的某动态规划题:糖果(openjudge->NOI->2.6->2989)