POJ 2502 Subway dij
这个题的输入输出注意一下就好
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;
const int N=4e3+;
const int INF=0x3f3f3f3f;
struct Edge{
int v,next;
double w;
bool operator<(const Edge &e)const{
return w>e.w;
}
}edge[N*N*];
int head[N],tot,n;
double d[N];
void add(int u,int v,double w){
edge[tot].v=v;
edge[tot].w=w;
edge[tot].next=head[u];
head[u]=tot++;
}
priority_queue<Edge>q;
bool vis[N];
double dij(int s,int t){
for(int i=;i<=n;++i)d[i]=INF,vis[i]=;
d[s]=,q.push(Edge{s,,});
while(!q.empty()){
while(!q.empty()&&vis[q.top().v])q.pop();
if(q.empty())break;
int u=q.top().v;
q.pop();
vis[u]=;
for(int i=head[u];~i;i=edge[i].next){
int v=edge[i].v;
if(!vis[v]&&d[v]>d[u]+edge[i].w){
d[v]=d[u]+edge[i].w;
q.push(Edge{v,,d[v]});
}
}
}
return d[t];
}
struct Point{
int x,y;
}p[N];
double dis(int i,int j){
return sqrt((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y));
}
int main(){
memset(head,-,sizeof(head)),tot=;
scanf("%d%d%d%d",&p[].x,&p[].y,&p[].x,&p[].y);
n=;
bool flag=;
while(~scanf("%d%d",&p[n].x,&p[n].y)){
if(p[n].x==-&&p[n].y==-){
flag=;
continue;
}
if(flag){
double tmp=dis(n,n-)/40000.0;
add(n,n-,tmp),add(n-,n,tmp);
}
flag=;
++n;
}
--n;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j){
if(i==j)continue;
double tmp=dis(i,j)/10000.0;
add(i,j,tmp),add(j,i,tmp);
}
printf("%d\n",(int)(dij(,)*60.0+0.5));
return ;
}
POJ 2502 Subway dij的更多相关文章
- 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 ...
- POJ 2502 - Subway Dijkstra堆优化试水
做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...
- POJ 2502 Subway(迪杰斯特拉)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6692 Accepted: 2177 Descriptio ...
- POJ 2502 Subway (Dijkstra 最短+建设规划)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6689 Accepted: 2176 Descriptio ...
- POJ 2502 Subway
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4928 Accepted: 1602 Descriptio ...
- POJ 2502 Subway (最短路)
Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...
- (简单) POJ 2502 Subway,Dijkstra。
Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of ...
- Dijkstra+计算几何 POJ 2502 Subway
题目传送门 题意:列车上行驶40, 其余走路速度10.问从家到学校的最短时间 分析:关键是建图:相邻站点的速度是40,否则都可以走路10的速度.读入数据也很变态. #include <cstdi ...
- poj 2502 Subway【Dijkstra】
<题目链接> 题目大意: 某学生从家到学校之间有N(<200)条地铁,这个学生可以在任意站点上下车,无论何时都能赶上地铁,可以从一条地铁的任意一站到另一条地跌的任意一站,学生步行速度 ...
随机推荐
- slabs.c
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* * Slabs memory allo ...
- std::string和int类型的相互转换(C/C++)
字符串和数值之前转换,是一个经常碰到的类型转换. 之前字符数组用的多,std::string的这次用到了,还是有点区别,这里提供C++和C的两种方式供参考: 优缺点:C++的stringstream智 ...
- MIT 2012分布式课程基础源码解析-事件管理封装
这部分的内容主要包括Epoll/select的封装,在封装好相应函数后,再使用一个类来管理相应事件,实现的文件为pollmgr.{h, cc}. 事件函数封装 可看到pollmgr.h文件下定一个了一 ...
- sql修改表结构、临时表应用
alter table dbo.P_ZPROMOTION_DOC_ITEMS_TEMP alter column MCRANK varchar(20); 方法一: use testdb --创建局部 ...
- DataTable数据进行排序、检索、合并、分页、统计
在做程序时经常遇到要将反复对数据进行筛选.求和.排序.分页等的情况.每次的数据操作都要去访问数据库很明显是不合理的!当然需要实时数据的情况除外,不做讨论哈.今天无意间在网上看到了这篇文章,挺实用的,拿 ...
- Oracle删除所有表
Oracle 清理用户所有的表 PLSQL中执行语句 select 'drop '||object_type||' '||object_name||';' from user_objects; 结果集 ...
- DB天气app冲刺第四天
今天卡壳了 做得很慢.. 明天继续 换一种思路试一下吧..
- SQL2008附加数据库提示错误:5120
前几天在附加数据库时,出现了这个错误 在win7 x64系统上使用sql2008进行附加数据库(包括在x86系统正在使用的数据库文件,直接拷贝附加在X64系统中)时,提示无法打开文 ...
- web中自定义鼠标样式
实现一个功能:鼠标移动到一个图片左边显示左箭头,移动到右边显示右箭头. 实现方法:一个img上面定位两个div,div的样式如下: .toleft { width: 200px; height: 30 ...
- Python中通过Image的open之后,去show结果打不开bmp图片,无法正常显示图片
在windows的cmd命令行下,使用Python的PIL库打开并显示一个jpg图片: ? 1 2 3 openedImg = Image.open(saveToFile); print " ...