HDU-2363 Cycling
来源:互联网 发布:淘宝助理大头笔设置 编辑:程序博客网 时间:2024/06/04 22:08
求海拔差最小的前提下的最短路
思路:暴力搜索 =。=
TL了无数次 只因没判重 欲哭无泪QAQ
#include "stdio.h"#include "string.h"#include "vector"#include "queue"#include "algorithm"using namespace std;const int maxn = 105;const int inf = 1000000001;int n,m;int h[maxn];int map[maxn][maxn];bool vis[maxn];struct node{ int v,dis; int Max,Min; bool operator <( const node &x )const { if( Min != x.Min ) return Min < x.Min; if( Max != x.Max ) return Max > x.Max; return dis > x.dis; }}P[maxn];void BFS( int s,int e ){ node cur,cnt; int ans = inf,dist = inf; priority_queue<node>que; for( int i = 1; i <= n; i ++ ) { P[i].dis = P[i].Max = inf; P[i].Min = 0; P[i].v = i; } P[s].dis = 0; P[s].Max = P[s].Min = h[s]; que.push(P[s]); while( !que.empty() ) { cur = que.top(); que.pop(); if( cur.v == e ) { if( cur.Max - cur.Min < ans ) { ans = cur.Max - cur.Min; dist = cur.dis; } else if( cur.Max - cur.Min == ans && dist > cur.dis ) { dist = cur.dis; } } for( int i = 1; i <= n; i ++ ) { if( map[cur.v][i] != inf ) { int Max = cur.Max > h[i]?cur.Max:h[i]; int Min = cur.Min < h[i]?cur.Min:h[i]; if( !( Max >= P[i].Max && Min <= P[i].Min && cur.dis + map[cur.v][i] >= P[i].dis || Max - Min > ans) ) { P[i].dis = cur.dis + map[cur.v][i]; P[i].Max = Max; P[i].Min = Min; que.push(P[i]); } } } } printf("%d %d\n",ans,dist);}int main(){ //freopen( "1.txt","r",stdin ); int t,u,v,w; scanf("%d",&t); while( t-- ) { scanf("%d%d",&n,&m); for( int i = 1; i <= n; i ++ ) for( int j = 1; j <= n; j ++ ) map[i][j] = inf; for( int i = 1; i <= n; i ++ ) scanf("%d",&h[i]); for( int i = 1; i <= m; i ++ ) { scanf("%d%d%d",&u,&v,&w);if( map[u][v] > w ) map[u][v] = map[v][u] = w; } BFS(1,n); } return 0;}
- HDU-2363 Cycling
- HDU-2363-Cycling
- 【HDU】2363 Cycling 最短路
- hdu 2363 Cycling Dijkstra最短路
- HDU 2363 Cycling(枚举+最短路)
- HDU 2363 Cycling 最短路+枚举
- HDU 2363 Cycling 枚举限制+最短路
- HDU 2363 Cycling 二分+ 限制最短路
- HDU 2363 Cycling(并查集 SPFA 暴力枚举)
- hdu 2363 Cycling (最短路spfa + 暴力枚举)
- Cycling
- HDU 2363 Cycling(二分+枚举+限制最短路,好题)
- 【最短路】HDOJ 2363 Cycling
- p1946_cow cycling
- I love cycling!
- POJ 1946 Cow Cycling
- poj 1946 Cow Cycling
- POJ 1946 Cow Cycling
- 八皇后问题 EightQueen
- android attr.xml文件
- 怎么查询端口被占用
- 第10周项目1:1000之内的所有偶数和(法1)
- ARC:retain cycle 导致的一个内存警告问题
- HDU-2363 Cycling
- Linux一些基础知识总结
- cocos2dx几种菜单按钮(CCMenu)的建立以及播放按钮的切换效果
- 小媛在努力
- android 常见分辨率(mdpi、hdpi 、xhdpi、xxhdpi )及屏幕适配注意事项
- SSH到某个机器的时候出现WARNING: REMOTE HOST IDENTIFICATION HASCHANGED!
- linq where 中两个条件
- 为什么我们还在用Android
- linux 安装 Gitk 和 GitGui