POJ 1922 解题报告
2015-06-12 07:13
281 查看
这道题其实是个智力题。
重点在于:
1.首先,不考虑提前出发的选手。除此之外,所有选手在0时刻都在起点。这些 “正常的”选手从出发开始,做的就是匀速运动,直到终点。所以答案就是这些选手中最先到达的时间。因为如果这样的选手如果超过了别人,第一个到达,那么在这个过程(超过别人)中,搭车人会搭他的车一同到达。
2.提前出发的选手可以直接忽略。因为,如果他们没有被超过,那么搭车人一直没机会遇到他们,如果被超过了,就更没有考虑的必要了。
除法的精度也是需要考虑的一个问题,4500 * 3.6 / speed能过而4500 / (speed / 3.6)不能过。前者有更高的精度。
重点在于:
1.首先,不考虑提前出发的选手。除此之外,所有选手在0时刻都在起点。这些 “正常的”选手从出发开始,做的就是匀速运动,直到终点。所以答案就是这些选手中最先到达的时间。因为如果这样的选手如果超过了别人,第一个到达,那么在这个过程(超过别人)中,搭车人会搭他的车一同到达。
2.提前出发的选手可以直接忽略。因为,如果他们没有被超过,那么搭车人一直没机会遇到他们,如果被超过了,就更没有考虑的必要了。
除法的精度也是需要考虑的一个问题,4500 * 3.6 / speed能过而4500 / (speed / 3.6)不能过。前者有更高的精度。
thestoryofsnow | 1922 | Accepted | 156K | 16MS | C++ |
/* 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; }
相关文章推荐
- JavaScript中产生标识符方式的演变
- 9 Ways to Instantly Strengthen Your Brain
- Test4002
- android 中应用SQLite 常用自增ID,ID归零方法
- OSChina 周五乱弹 —— 快使用PHP,哼哼哈兮
- Test 3002
- CentOS yum安装Apache + PHP + MySQL + Tomcat
- 天题系列: Candy
- Test3001
- char *指针的详细解释
- Test 2002
- 海量路由表的快速检索问题-Hash/Trie/快速交换
- 海量路由表的快速检索问题-Hash/Trie/快速交换
- Test 2001
- Test_1002
- Test1001
- [POJ 1273] Drainage Ditches & 最大流Dinic模板
- Win7下IIS安装PHP环境
- 在TMemo上画一条线
- Gas Station