Subway

Time Limit: 1000MS Memory Limit: 65536K

Description

You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don't want to be late for class, you want to know how long it will take you to get to school.

You walk at a speed of 10 km/h. The subway travels at 40 km/h. Assume that you are lucky, and whenever you arrive at a subway station, a train is there that you can board immediately. You may get on and off the subway any number of times, and you may switch between different subway lines if you wish. All subway lines go in both directions.

Input

Input consists of the x,y coordinates of your home and your school, followed by specifications of several subway lines. Each subway line consists of the non-negative integer x,y coordinates of each stop on the line, in order. You may assume the subway runs in a straight line between adjacent stops, and the coordinates represent an integral number of metres. Each line has at least two stops. The end of each subway line is followed by the dummy coordinate pair -1,-1. In total there are at most 200 subway stops in the city.

Output

Output is the number of minutes it will take you to get to school, rounded to the nearest minute, taking the fastest route.

Sample Input

0 0 10000 1000

0 200 5000 200 7000 200 -1 -1

2000 600 5000 600 10000 600 -1 -1

Sample Output

21

Source

Waterloo local 2001.09.22

题意:输入家的位置,学校的位置,然后知道几条地铁的站点,然后求到学校的时间最短时间。

题解:这道题有点懵逼,首先是输入,没有告知地铁的条数,知道告诉每条地铁到(-1,,1)结束。也就是说地铁输入到EOF才会结束。难点就在如何输入上,剩下的就是模板了。注意他的时速单位是KM,但是坐标单位是M。注意:地铁站点只能一个站点到下一个站点。(从1站到3三站,你必须经过2站才能到3站)

附上代码

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <map> using namespace std;
const int maxn = 205;
const int INF = 1e9+7;
const double h = 40*1000.0/60.0;
const double r = 10*1000.0/60.0; struct node
{
double x,y;
}p[maxn]; double s[maxn][maxn];
int num; int judge(double x,double y)
{
int i;
for(i=0;i<num;i++)
if(p[i].x==x&&p[i].y==y)
return i;
if(i==num)
{
p[num].x = x;
p[num++].y = y;
}
return i;
} double get_dis(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} void dijkstra()
{
double dis[maxn],MIN;
int i,j,f[maxn],k;
for(i=0;i<num;i++)
{
f[i] = 0;
dis[i] = s[0][i];
}
f[0] = 1;
for(i=0;i<num;i++)
{
MIN = INF;
k = -1;
for(j=0;j<num;j++)
{
if(!f[j]&&dis[j]<MIN)
{
MIN = dis[j];
k = j;
}
}
if(MIN == INF)
break;
f[k] = 1;
for(j=0;j<num;j++)
if(!f[j]&&dis[k]+s[k][j]<dis[j])
dis[j] = dis[k] + s[k][j];
}
printf("%.0f\n",dis[1]);
} int main()
{
int i,j,a,b;
int link[maxn],n;
double dis;
for(i=0;i<maxn;i++)
for(j=0;j<maxn;j++)
s[i][j] = (i==j)?0:INF;
node q;
scanf("%lf%lf",&p[0].x,&p[0].y);
scanf("%lf%lf",&p[1].x,&p[1].y);
num = 2;
//int k = 0;
while(scanf("%lf%lf",&q.x,&q.y)!=EOF)
{
n = 0;
link[n++] = judge(q.x,q.y);
while(scanf("%lf%lf",&q.x,&q.y))
{
if(q.x==-1&&q.y==-1)
break;
link[n++] = judge(q.x,q.y);
}
for(i=0;i<n-1;i++)
{
a = link[i];
b = link[i+1];
dis = get_dis(p[a],p[b]);
s[a][b] = s[b][a] = min(s[a][b],dis/h);
}
// for(i=0;i<n;i++)
// {
// a = link[i];
// cout<<a<<":";
// printf("%.0f %.0f\n",p[a].x,p[a].y);
// }
// k++;
// if(k==2)
// break;
}
for(i=0;i<num;i++)
for(j=0;j<i;j++)
{
dis = get_dis(p[i],p[j]);
s[i][j] = s[j][i] = min(s[i][j],dis/r);
}
// for(i=0;i<num;i++)
// {
// for(j=0;j<num;j++)
// printf("%.0f ",s[i][j]);
// printf("\n");
// }
dijkstra();
return 0;
}

POJ-2502_Subway的更多相关文章

  1. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  2. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  3. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  4. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  5. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  8. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  9. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

  10. poj 1251 Jungle Roads (最小生成树)

    poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...

随机推荐

  1. LUOGU P2939 [USACO09FEB]改造路Revamping Trails

    题意翻译 约翰一共有N)个牧场.由M条布满尘埃的小径连接.小径可 以双向通行.每天早上约翰从牧场1出发到牧场N去给奶牛检查身体. 通过每条小径都需要消耗一定的时间.约翰打算升级其中K条小径,使之成为高 ...

  2. 一些CSS知识点备忘

    RGBA指的是“红色.绿色.蓝色和Alpha透明度”(Red-Green-Blue-Alpha). HSLA代表“色调.饱和度.亮度和Alpha透明度”(Hue-Saturation-Lightnes ...

  3. JS简单实现:根据奖品权重计算中奖概率实现抽奖的方法

    本文主要介绍:使用 JS 根据奖品权重计算中奖概率实现抽奖的方法. 一.示例场景 1.1.设置抽奖活动的奖项名称 奖项名称:["一等奖", "二等奖", &qu ...

  4. 使用Jedis操作Redis-使用Java语言在客户端操作---List类型

    在Redis中,List类型是按照插入顺序排序的字符串链表.和数据结构中的普通链表一样,我们可以在其头部(left)和尾部(right)添加新的元素.在插入时,如果该键并不存在,Redis将为该键创建 ...

  5. Java 类与类之间的调用

    方法1. 新建一个类. 然后在调用类中先进行被调用类实例化,然后通过实例化的对象访问. 例如: //先定义一个类 import static java.lang.System.out; public ...

  6. zk运维注意事项

    1 连接数容易占满 2 watches数 (应用上的比较多建议做个自动监控,告警)

  7. Angular.js的自定义功能

    1,自定义指令,在html中输入标签显示想要的指令 html script部分 2,标签中的属性的 有属性值时可以通过函数的参数返回属性值 没有属性值时可以设置属性值(自定义属性值) html部分   ...

  8. 集训队日常训练20180525-DIV1

    A.2805 N*M的图,每次浇水(X1,Y1)-(X2,Y2)围成的矩形,问最后有多少点被浇水了. 暴力. #include<bits/stdc++.h> using namespace ...

  9. Winform实现调用asp.net数据接口实例

    本文实例讲述了Winform实现调用asp.net数据接口的方法,分享给大家供大家参考.具体实现方法如下: 一.问题: 最近一个WPF项目需要改写成android项目,思路是在asp.net项目中编写 ...

  10. Android——内存管理基础

    内存收集概念 内存垃圾收集器(garbage collector) 概念:自定内存管理. 功能:分配内存.保证所有被引用的对象还在内存中.可以释放在运行的代码中不再引用的对象的内存. 垃圾收集器避免了 ...