dij部分还是跟模板差不多的 但是这题的难点是处理输入 或者说理解题意

事实上每个点之间都是可以走的......WA了好几发就因为没意识到同一条路线上的各个站点之间居然也可以走得比车子快....

PS: POJ的C++编译器居然没法自动识别sqrt函数用哪个=.=

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#define INF 1e30
using namespace std; typedef pair<double, int> pdi;
struct cmp{
bool operator () (const pdi a, const pdi b){
return a.first > b.first;
}
}; struct Node{
int x, y;
}node[];
//int pre[210];
double val[][], dis[]; double DISTANCE(int a, int b){
return sqrt((double)((node[a].x - node[b].x) * (node[a].x - node[b].x) +
(node[a].y - node[b].y) * (node[a].y - node[b].y)));
} void dij(int s, int n)
{
//memset(pre, -1 ,sizeof pre);
for(int i = ; i <= n; i++){
dis[i] = INF;
}
priority_queue<pdi, vector<pdi>, cmp> q;
q.push(make_pair(, ));
dis[] = ;
while(!q.empty()){
pdi u = q.top();
q.pop();
if(u.first > dis[u.second]) continue;
for(int i = ; i <= n; i++){
if(i != u.second && dis[i] > dis[u.second] + val[u.second][i]){
dis[i] = dis[u.second] + val[u.second][i];
//pre[i] = u.second;
q.push(make_pair(dis[i], i));
}
}
}
}
int main()
{
int size = ;
for(int i = ; i < ; i++){
for(int j = ; j < ; j++){
val[i][j] = INF;
}
}
scanf("%d%d%d%d", &node[].x, &node[].y, &node[].x, &node[].y);
val[][] = val[][] = DISTANCE(, ) / * ;
while(~scanf("%d%d", &node[size].x, &node[size].y)){
int a, b;
size++;
while(scanf("%d%d", &a, &b), ~a || ~b){
node[size].x = a;
node[size].y = b;
val[size-][size] = val[size][size-]
= DISTANCE(size, size-) / * ;
size++;
}
}
for(int i = ; i < size; i++){
for(int j = ; j < size; j++){
val[i][j] = min(val[i][j], DISTANCE(i, j) / * );
}
}
dij(, size - );
printf("%.0lf\n", dis[]);
/*for(int i = 1; i < size; i++){
printf("x%d = %-8d y%d = %-8d\n", i, node[i].x, i, node[i].y);
}
for(int i = 1; i < size; i++){
for(int j = 1; j < size; j++){
printf("[%d][%d] = %-3.0lf", i, j, val[i][j]);
}
putchar('\n');
}
for(int i = 2; ~i; i = pre[i]){
printf("pre = %d\n", i);
}*/
return ;
}

kuangbin_ShortPath L (POJ 2502)的更多相关文章

  1. POJ 2502 - Subway Dijkstra堆优化试水

    做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...

  2. POJ 2502 Subway / NBUT 1440 Subway / SCU 2186 Subway(图论,最短距离)

    POJ 2502 Subway / NBUT 1440 Subway / SCU 2186 Subway(图论,最短距离) Description You have just moved from a ...

  3. L - Subway - POJ 2502

    题意:在一个城市里,分布着若干条地铁线路,每条地铁线路有若干个站点,所有地铁的速度均为40km/h.现在你知道了出发地和终点的坐标,以及这些地铁 线路每个站点的坐标,你的步行速度为10km/h,且你到 ...

  4. POJ 2502 最短路

    http://poj.org/problem?id=2502 同一条地铁线上的站点相邻点间按照v2建边,然后所有点之间按照v1更新建边,所有的边都是双向边,both directions. 然后直接跑 ...

  5. Subway POJ 2502

    题目链接: http://poj.org/problem?id=2502 题目大意: 你刚从一个安静的小镇搬到一个吵闹的大城市,所以你不能再骑自行车去上学了,只能乘坐地铁或者步行去上学.因为你不想迟到 ...

  6. POJ 2502 Subway(迪杰斯特拉)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6692   Accepted: 2177 Descriptio ...

  7. POJ 2502 Subway (Dijkstra 最短+建设规划)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6689   Accepted: 2176 Descriptio ...

  8. Dijkstra+计算几何 POJ 2502 Subway

    题目传送门 题意:列车上行驶40, 其余走路速度10.问从家到学校的最短时间 分析:关键是建图:相邻站点的速度是40,否则都可以走路10的速度.读入数据也很变态. #include <cstdi ...

  9. kuangbin_ShortPath J (POJ 1511)

    其实虽然一开始有被这个题的8000MS 和 256MB限制又被吓到 但是严格来说跟之前的POJ 3268是一样的做法只是数据大了点 但是问题就出在数据大了点上 其实严格来说也不大 1e6 数组加起来大 ...

随机推荐

  1. Spring AOP中pointcut expression表达式解析 及匹配多个条件

    Spring中事务控制相关配置: <bean id="txManager" class="org.springframework.jdbc.datasource.D ...

  2. 提示框alertmsg

    初始化: 1.Data属性:DOM添加属性data-toggle="alertmsg",并定义type及msg参数 示例代码: <button type="butt ...

  3. PHP同一个IP绑定多个域名(六)

    原理图 一个ip绑定如何绑定多个域名? 解决方案: A.方案一:端口号来区别不同的站点 1.绑定一个网站 1.1先开发好自己的网站 d:/ApacheProject/myanimal 1.2 配置我们 ...

  4. 一个很好介绍js的例子

    function UpdateInit(opt){ this.init(opt);} UpdateInit.prototype={ loadUrl:null, loadParam:null, befo ...

  5. PHP中的文件下载

    文件下载:用<a href="链接"></a>这种是下载,但对于浏览器能解释的文件类型此下载非彼下载.向服务器请求的时候:1.协议和版本2.头信息3.请求的 ...

  6. linux命令:cd

    1.介绍: cd可以说是linux下最基本的命令,全称是change directory. 2.命令格式: cd [DIRECTORY] 3.命令功能: 切换到指定目录 4.常用范例: 例一:切换到根 ...

  7. 2、SQL基础整理(聚合函数)

    聚合函数 --求平均 select  AVG(age) as 年龄 from xuesheng select AVG(chinese) as 语文 from xuesheng where class ...

  8. centOS7 修改hostname

    hostnamectl set-hostname 你要修改到的hostname   localectl set-locale LANG=要修改的语言     介绍个Centos 7很不错的教程网站:h ...

  9. 如何避免后台IO高负载造成的长时间JVM GC停顿(转)

    译者著:其实本文的中心意思非常简单,没有耐心的读者建议直接拉到最后看结论部分,有兴趣的读者可以详细阅读一下. 原文发表于Linkedin Engineering,作者 Zhenyun Zhuang是L ...

  10. java实现读取文件大全

    1.按字节读取文件内容 2.按字符读取文件内容 3.按行读取文件内容 4.随机读取文件内容 public class ReadFromFile { /** * 以字节为单位读取文件,常用于读二进制文件 ...