zoj 2048 Highways poj 1751
来源:互联网 发布:北京四达时代通讯网络 编辑:程序博客网 时间:2024/05/16 10:29
两题几乎就是一摸一样的,只是输入格式不一样。
#include <iostream>#include <algorithm>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;const int MAX = 1000;const int INF = 10000010;struct Point{ int x,y;} point[MAX];int dist[MAX],edge[MAX][MAX];int n,m;void Inite(){int i, j;int a, b;cin>>n; for(i=1; i<=n; i++) { cin>>point[i].x>>point[i].y; } for(i=1; i<=n; i++) { edge[i][i] = 0; } for(i=1; i<=n; i++) { for(j=1; j<=n; j++) { if(i != j)edge[i][j] = (point[i].x - point[j].x) * (point[i].x - point[j].x) + (point[i].y - point[j].y) * (point[i].y - point[j].y); } } cin>>m; for(i=1; i<=m; i++) { cin>>a>>b; edge[a][b] = edge[b][a] = 0; }}void prim(){ int i,j,v;int index[MAX]; for(i=1; i<=n; i++) { dist[i] = edge[1][i]; index[i] = 1; } index[1] = -1; for(j=1; j<n; j++) { int min = INF; v = -1; for(i=1; i<=n; i++) { if(index[i] != -1 && min > dist[i]) { min = dist[i]; v = i; } } if(v != -1) { if(min != 0) cout<<index[v]<<" "<<v<<endl; index[v] = -1; for(i=1; i<=n; i++)//更新值 { if(index[i] != -1 && edge[v][i] < dist[i]) { dist[i] = edge[v][i]; index[i] = v; } } } }}int main(){int T;cin>>T; while(T--){Inite();prim();if(T != 0)cout<<endl;} return 0;}
- zoj 2048 Highways poj 1751
- zoj 2048 && poj 1751 Highways
- ZOJ 2048 POJ 1751 Highways
- POJ 1751 Highways (ZOJ 2048 ) MST
- ZOJ 2048 / POJ 2485 Highways ( kruskal )
- zoj 2048 Highways(Kruskal~)
- ZOJ 2048 Highways【kruskal】
- zoj - 2048 - Highways
- zoj 2048 Highways
- ZOJ 2048 highways
- ZOJ 2048 :Highways 【Prim】
- poj 1751 Highways
- poj 1751 highways
- Poj 1751 Highways(prim)
- poj 1751 Highways
- poj 1751 Highways MST
- POJ-1751-Highways
- POJ:1751 Highways
- STM8 测量脉宽——红外例程
- 实用新工具 我要关机(CloseMyPC)
- Qt for Android 5.2.0体验
- 【移动开发】Android中三种超实用的滑屏方式汇总(ViewPager、ViewFlipper、ViewFlow)
- C#对象序列化
- zoj 2048 Highways poj 1751
- kd tree
- 正则表达式中的反向引用
- PowerDesigner15.1汉化+注册补丁
- ZooKeeper 典型的应用场景
- CountDownLatch简述
- HDU 2037 - 今年暑假不AC(贪心 + 动态)
- c/c++static
- C#中调用VC编写的dll库