您的位置:首页 > 其它

POJ 1922 解题报告

2015-06-12 07:13 281 查看
这道题其实是个智力题。

重点在于:

1.首先,不考虑提前出发的选手。除此之外,所有选手在0时刻都在起点。这些 “正常的”选手从出发开始,做的就是匀速运动,直到终点。所以答案就是这些选手中最先到达的时间。因为如果这样的选手如果超过了别人,第一个到达,那么在这个过程(超过别人)中,搭车人会搭他的车一同到达。

2.提前出发的选手可以直接忽略。因为,如果他们没有被超过,那么搭车人一直没机会遇到他们,如果被超过了,就更没有考虑的必要了。

除法的精度也是需要考虑的一个问题,4500 * 3.6 / speed能过而4500 / (speed / 3.6)不能过。前者有更高的精度。

thestoryofsnow1922Accepted156K16MSC++
/*
ID: thestor1
LANG: C++
TASK: poj1922
*/
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <limits>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cassert>

using namespace std;

const int DIS = 4500;

int main()
{
int n;
while (scanf("%d", &n) == 1 && n)
{
int speed, starttime, mintime = -1;
for (int i = 0; i < n; ++i)
{
scanf("%d%d", &speed, &starttime);
if (starttime < 0)
{
continue;
}

int arrivaltime = ceil(starttime + DIS * 3.6 / speed);
if (mintime < 0 || arrivaltime < mintime)
{
mintime = arrivaltime;
}
}
printf("%d\n", mintime);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: