北大1022题

来源:互联网 发布:macbook下载什么软件 编辑:程序博客网 时间:2024/05/22 06:56

题目连接:http://acm.cust.edu.cn:8081/JudgeOnline/showproblem?problem_id=1022

这道题挺有意思,分析一下才能知道要求的其实是与A同时出发或者在A之后出发最早到达目的地的时间

 

include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

#define MAX 20

struct Rider
{
 int v;
 double t;
};

bool Less(Rider r1,Rider r2)
{
 return r1.t <= r2.t;
}

bool LLess(Rider r1,Rider r2)
{
 return r1.t <= r2.t;
}

int main()
{
 freopen("i.txt","r",stdin);

 int i,n,t;
 Rider r[MAX];

 while(cin >> n && n)
 {
  for(i = 0;i < n;++i)
   cin >> r[i].v >> r[i].t;
  sort(r,r+n,Less);

  for(i = 0;r[i].t < 0;++i);
  t = i;
  while(i < n)
  {
   r[i].t += 4500.0 * 3.6 / r[i].v;
   ++i;
  }

  sort(r+t,r+n,LLess);
  cout << ceil(r[t].t) << endl;
 }
 return 0;
}