Uva - 10034 - Freckles
来源:互联网 发布:最好用的编程软件 编辑:程序博客网 时间:2024/05/17 01:55
题意:有n个斑点,用直线连起来使任意两点连通,求最短的画线距离和(0 < n <= 100)。
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21276
——>>白白净净的最小生成树。
另外发现了一个问题:每组数据(最后一组除外)后漏了空行,返回的是WA,不是CE!
#include <cstdio>#include <cmath>#include <queue>using namespace std;const int maxn = 100 + 10;int n, fa[maxn];struct Point{ double x; double y;}p[maxn];double Dis(Point A, Point B){ return sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));}struct node{ int u; int v; double dis; bool operator < (const node& e) const{ return dis > e.dis; }};void read(){ scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%lf%lf", &p[i].x, &p[i].y);}int Find(int x){ return fa[x] == x ? x : fa[x] = Find(fa[x]);}bool Union(int x, int y){ int newx = Find(x); int newy = Find(y); if(newx == newy) return 0; fa[newy] = newx; return 1;}void init(){ for(int i = 0; i < n; i++) fa[i] = i;}void Kruscal(){ priority_queue<node> pq; for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++) pq.push((node){i, j, Dis(p[i], p[j])}); init(); double ret = 0; while(!pq.empty()){ node no = pq.top(); pq.pop(); if(Union(no.u, no.v)) ret += no.dis; } printf("%.2f\n", ret);}int main(){ int T; scanf("%d", &T); while(T--){ read(); Kruscal(); if(T) puts(""); } return 0;}
- UVa 10034 Freckles
- UVa 10034 Freckles
- UVa 10034 Freckles
- UVA 10034 - Freckles
- UVA:10034 - Freckles
- UVa 10034 - Freckles
- UVa 10034 Freckles 解答
- UVA 10034 - Freckles
- Uva 10034 - Freckles
- UVA 10034 Freckles
- UVa 10034: Freckles
- UVa:10034 Freckles
- Uva - 10034 - Freckles
- UVA - 10034 Freckles
- UVa 10034 - Freckles
- Uva 10034 - Freckles
- UVA 10034 - Freckles
- uva 10034 - Freckles
- DOM编程之八
- HDU1115-凸包
- LINUX驱动注册过程失败处理不当引起的恶果
- SilkTest入门快打2-编写脚本测试
- 10、从零开始学习JAVA--抽象类和抽象函数
- Uva - 10034 - Freckles
- UVA 607 Scheduling Lectures
- SilkTest入门快打3-函数与原生Verify函数
- 如何打开扩展名为.DB 文件. 使用sqlite3 很方便
- 冒泡排序
- Linux下多任务间通信和同步-管道
- MySQL的information_schema的介绍
- SAP 公司间销售配置原理和步骤
- exit和return区别