poj-2349 Arctic Network 最小生成树
2014-07-27 15:01
579 查看
题目链接
#include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int maxn = 1005; const int Mod = 1000000007; int s,n,m,c; double ans; struct Node { int x,y; }point[maxn]; struct node { int u,v; double w; }edge[maxn*maxn]; int p[maxn]; bool cmp( node a,node b ) { return a.w < b.w; } int find( int x ) { return x == p[x]?x:p[x] = find( p[x] ); } void merge( node s ) { int x = find( s.u ); int y = find( s.v ); if( x != y ) { p[x] = y; c ++; ans = s.w; } } int main() { #ifndef ONLINE_JUDGE freopen("data.txt","r",stdin); #endif int cas; scanf("%d",&cas); while( cas -- ) { scanf("%d%d",&s,&n); ans = m = c = 0; for( int i = 1; i <= n; i ++ ) { scanf("%d%d",&point[i].x,&point[i].y); } for( int i = 1; i <= n; i ++ ) { for( int j = i+1; j <= n; j ++ ) { edge[m].u = i; edge[m].v = j; edge[m++].w = sqrt( (( point[i].x - point[j].x )*( point[i].x - point[j].x ) + ( point[i].y - point[j].y )*( point[i].y - point[j].y ))*1.0 ); } } sort( edge,edge+m,cmp ); for( int i = 0; i <= n; i ++ ) p[i] = i; for( int i = 0; i < m; i ++ ){ merge( edge[i] ); if( c == n - s ) break; } printf("%.2lf\n",ans); } return 0; }
相关文章推荐
- poj 2349 Arctic Network(最小生成树的第k大边证明)
- POJ 2349 Arctic Network (最小生成树第K大(小)边)
- POJ 2349 Arctic Network 最小生成树题解
- POJ 2349 Arctic Network(最小生成树之Prim)
- poj 2349 Arctic Network(图论:最小生成树)
- Arctic Network (poj 2349 最小生成树)
- POJ 2349 Arctic Network(最小生成树,第k大边权,基础)
- POJ 2349 Arctic Network(最小生成树思想)
- poj 2349 Arctic Network(最小生成树变形)
- Prim最小生成树【poj 2349 Arctic Network;poj 1287 NetWorking】
- POJ 2349 Arctic Network(最小生成树 kruscal or prim)
- poj 2349 (最小生成树)Arctic Network
- POJ - 2349 Arctic Network (最小生成树分块)
- POJ 2349 Arctic Network [最小生成树]
- 2349 poj &&uva 10369 Arctic Network【最小生成树】
- poj 2349 Arctic Network(最小瓶颈生成树)
- poj 2349 Arctic Network 最小生成树,求第k大条边
- poj 2349 Arctic Network 最小生成树
- POJ 2349 Arctic Network 最小生成树
- 【POJ】2349 - Arctic Network(最小生成树的第n条大边)(好题)