Subway POJ - 2502 spfa
- #include<cstdio>
- #include<cmath>
- #include<cstring>
- #include<cstring>
- #include<iostream>
- #include<queue>
- using namespace std;
- const int N=;
- const double INF=0x3f3f3f3f;
- int k,l;
- struct node
- {
- double x,y;
- int num;
- } s[N];
- bool st[N];
- double dist[N];
- void spfa(int x)
- {
- memset(st,false,sizeof st );
- for(int i=;i<N;i++)
- dist[i]=INF;
- st[x]=true;
- dist[x]=;
- queue<int>q;
- while(!q.empty())
- q.pop();
- q.push(x);
- while(!q.empty())
- {
- int u=q.front();
- st[u]=false;
- q.pop();
- for(int i=; i<=k; i++)
- {
- if(i==u)
- continue;
- double far,t;
- far=sqrt(((s[u].y-s[i].y)*(s[u].y-s[i].y))+((s[u].x-s[i].x)*(s[u].x-s[i].x)));
- far=far/1000.0;
- if(fabs(s[u].num-s[i].num)==)
- t=far/40.0;
- else
- t=far/10.0;
- if(dist[i]>dist[u]+t)
- {
- dist[i]=dist[u]+t;
- if(!st[i])
- {
- st[i]=true;
- q.push(i);
- }
- }
- }
- }
- }
- int main()
- {
- double s1,s2,e1,e2;
- double x,y;
- k=,l=;
- cin>>s1>>s2>>e1>>e2;
- //只有相邻的站点能到
- while(cin>>x>>y)
- {
- if(x==-&&y==-)
- {
- if(l==)
- break;
- l++;
- continue;
- }
- s[k].x=x,s[k].y=y;
- s[k++].num=l++;
- }
- s[].x=s1,s[].y=s2,s[].num=-;
- s[k].x=e1,s[k].y=e2,s[k].num=-;
- spfa();
- //四舍五入
- cout<<(int)(dist[k]*+0.5)<<endl;
- return ;
- }
Subway POJ - 2502 spfa的更多相关文章
- Subway POJ 2502
题目链接: http://poj.org/problem?id=2502 题目大意: 你刚从一个安静的小镇搬到一个吵闹的大城市,所以你不能再骑自行车去上学了,只能乘坐地铁或者步行去上学.因为你不想迟到 ...
- L - Subway - POJ 2502
题意:在一个城市里,分布着若干条地铁线路,每条地铁线路有若干个站点,所有地铁的速度均为40km/h.现在你知道了出发地和终点的坐标,以及这些地铁 线路每个站点的坐标,你的步行速度为10km/h,且你到 ...
- Subway POJ - 2502 最短路
题意:给出地铁线 起点和 终点 坐地铁速度为v2 走路为v1 求起点到终点的最短距离 (答案需要四舍五入这里坑了好久) 拿给出的地铁站点 和起点终点建边即可 然后跑个迪杰斯特拉 #inclu ...
- 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 ...
- L - Subway(最短路spfa)
L - Subway(最短路spfa) You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. In ...
- 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 ...
随机推荐
- Github搜索技巧
按仓库名称.说明或自述文件内容搜索 通过 in 限定符,您可以将搜索限制为仓库名称.仓库说明.自述文件内容或这些的任意组合. 如果省略此限定符,则只搜索仓库名称和说明. 限定符 示例 in:name ...
- dmock 基于Django的轻量级Mock平台
GitHub:https://github.com/yjlch1016/dmock # dmock 基于Django的轻量级Mock平台 dmock即Django+Mock的缩写 一.思路: mock ...
- ts中类的方法和抽象类
// 类里面的修饰符 typescript提供三种修饰符 /* public: 公有 在类里面.类外面.子类都可以访问 (默认不加就是public) protected: 保护 在类里面和子类可以访问 ...
- LAMP环境搭建+配置虚拟域名
Centos下PHP,Apache,Mysql 的安装 安装Apache yum -y install httpd systemctl start httpd 添加防火墙 firewall-cmd - ...
- mongo shell
mongo shell mongo 连接 本地 mongo # 连接127.0.0.1:27017 远程 mongo "mongodb://mongodb0.example.com:2801 ...
- equals和==的使用
1.equals的使用: 引用数据类型的比较:通常情况下比较的是引用数据类型下的栈中的地址,但当你重写了equals方法后就不一定了 User user1=new User("tom&quo ...
- ps调整图片指定区域的颜色,两种方法
参考链接:http://tech.wmzhe.com/article/12329.html
- 【笔记】机器学习 - 李宏毅 - 13 - Why Deep
当参数一样多的时候,神经网络变得更高比变宽更有效果.为什么会这样呢? 其实和软件行业的模块化思想是一致的. 比如,如果直接对这四种分类进行训练,长发的男孩数据较少,那么这一类训练得到的classifi ...
- 项目启动时报错:java.io.EOFException
解决方案 删除Tomcat里面的work\Catalina\localhost下的项目文件内容即可解决 问题原因 原因是由于项目测试中class文件或者其它文件更新过频繁
- (node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out after 30000 ms
记录一次学习node.js犯的低级错误 这里遇到一个这样的问题 express连接mongoose时报错(node:7584) UnhandledPromiseRejectionWarning: Mo ...