Elevators UVALive
来源:互联网 发布:简历管理系统知乎 编辑:程序博客网 时间:2024/05/20 01:46
题目链接:https://vjudge.net/problem/UVALive-7015
题意:n个电梯,每个电梯只能在特定的楼层停,若不换乘电梯,则从楼层x到楼层y所花费时间为abs(x-y),在某一楼层换乘电梯不消耗时间。求从当前所在楼层到目的楼层所需最小时间。
思路:输入中给的同一电梯相邻楼层建边,floyd求一次最短路,然后直接输出即可。
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<cstdlib>#include<sstream>#include<deque>#include<stack>#include<set>#include<map>using namespace std;typedef long long ll;typedef unsigned long long ull;const double eps = 1e-6;const int maxn = 2000 + 20;const int maxt = 300 + 10;const int mod = 10;const int dx[] = {1, -1, 0, 0};const int dy[] = {0, 0, -1, 1};const int Dis[] = {-1, 1, -5, 5};const int inf = 0x3f3f3f3f;const int MOD = 1000;int n, m, k;int dis[maxn][maxn];int num[maxn];int maxnnum;int floyd(){ for(int k = 0; k <= 150; ++k){ for(int i = 0; i <= 150; ++i){ for(int j = 0; j <= 150; ++j){ dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); } } }}int main(){ int a, b; while(~scanf("%d%d%d", &n, &a, &b)){ if(!n && !a && !b) break; for(int i = 0; i <= 150; ++i){ dis[i][i] = 0; for(int j = i + 1; j <= 150; ++j){ dis[i][j] = dis[j][i] = inf; } } memset(num, 0, sizeof num); int x, u, v; for(int i = 0; i < n; ++i){ scanf("%d", &x); scanf("%d", &num[0]); for(int j = 1; j < x; ++j){ scanf("%d", &num[j]); dis[num[j - 1]][num[j]] = dis[num[j]][num[j - 1]] = abs(num[j] - num[j - 1]); } } floyd(); printf("%d\n", dis[a][b]); } return 0;}
阅读全文
0 0
- Elevators UVALive
- Elevators UVALive
- 最短路 hnu13430 Elevators
- URAL 1901 Space Elevators(贪心)
- BNUOJ26429 Space Elevators(贪心)
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- jQuery基础语法
- Paint介绍
- java redis
- matlab2c使用c++实现matlab函数系列教程-compan函数
- 开启梦的航向
- Elevators UVALive
- linux磁盘管理
- 使用Java VisualVM监控JVM
- php 通过ssh2协议用sftp实现文件上传、下载
- 算法序列——最长公共子序列
- Step 8:Processing分形之三——Diffusion-Limited Aggregation
- 剑指Offer—33—丑数
- C++ 字节对齐(class 与struct)
- 好用的 CURL 类