51Nod 1445(考建图的最短路)
来源:互联网 发布:阿里云服务器屏蔽ip 编辑:程序博客网 时间:2024/06/03 20:47
N只有50,跑一下N的平方建图,两种颜色之间的距离就是 他前面的Y的数量,剩下的就是模板了。
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<set>#include<queue>using namespace std;typedef long long ll;typedef pair<int,int > P;const int maxn = 55;const int inf = 1<<20;int n;char bmap[maxn][maxn] ;int edge[maxn][maxn];int dist[maxn];struct node{ int id; int dist; bool operator < (const node& T) const{ return dist>T.dist; } node(int a,int b):id(a),dist(b){}};void dij(){ for(int i=0;i<n;i++) dist[i] = inf; priority_queue<node>q; q.push(node(0,0)); dist[0] = 0; while(!q.empty()) { node fr = q.top(); q.pop(); int u = fr.id; //printf("%d\n",u); for(int i=0;i<n;i++) { if(dist[i]>dist[u]+edge[u][i]) { //printf("sdfsdfsdfsdfsd\n"); dist[i] = dist[u] + edge[u][i]; q.push(node(i,dist[i])); } } } if(dist[n-1]>=inf) printf("-1\n"); else printf("%d\n",dist[n-1]);}int main(){ int cases; scanf("%d",&cases); while(cases--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%s",bmap[i]); for(int i=0;i<n;i++) { int sum = 0; for(int j=0;j<n;j++) { if(bmap[i][j]=='N') {edge[i][j] = inf; continue;} edge[i][j] = sum++; } } dij(); } return 0;}
阅读全文
0 0
- 51Nod 1445(考建图的最短路)
- 51nod 1445:变色DNA(最短路变形)
- 51nod 1445 变色DNA(最短路)
- 51nod 1366 贫富差距(最短路)
- 51 nod 1693 水群(最短路)
- 51nod 1326 遥远的旅途 最短路建模
- 51nod 1445:变色DNA 最短路变形
- 51nod 1445 变色DNA【最短路SPFA+思维】
- 51nod 1445:变色DNA 最短路变形
- 51nod 1459 迷宫游戏(最短路)
- 51nod 1459 迷宫游戏(最短路)
- 51nod 1459 迷宫游戏(最短路)
- 51nod 1649 齐头并进 (两次dijkstra求最短路)
- 51nod 1459 迷宫游戏 (最短路)
- 51nod 1459 迷宫游戏 最短路
- 51nod 1444 破坏道路 最短路
- 51nod 1444 破坏道路 最短路
- 51nod 1693 水群(spfa最短路)
- MVP模式初探
- docker 基本使用
- 561. Array Partition I
- 动态规划——背包问题
- HttpImage(网络请求图片)
- 51Nod 1445(考建图的最短路)
- 【QT】QObject简介
- SparseArray、ArrayMap 实现原理学习
- jQuery Growl 消息提醒插件
- openstack使用openvswitch实现vxlan组网
- 10道典型的JavaScript面试题
- android的日常错误集合
- js事件处理
- HDU2571 命运(dp问题)