POJ 2349 Arctic Network
来源:互联网 发布:淘宝订单不付钱 编辑:程序博客网 时间:2024/06/16 16:47
Arctic Network #include<stdio.h>#include<math.h>#include<algorithm>using namespace std;int father[550], m, k;double d[550];struct post{ double x, y;}p[550];struct edge{ int u, v; double w;}e[500005];bool comp(edge e1, edge e2){ return e1.w < e2.w;}double get_dis(double x1, double y1, double x2, double y2){ return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}void Init(int n){ for(int i = 1; i <= n; i++) father[i] = i;}int Find(int x){ if(x != father[x]) father[x] = Find(father[x]); return father[x];}void Merge(int a, int b){ int p = Find(a); int q = Find(b); if(p > q) father[p] = q; else father[q] = p;}void Kruskal(int n){ k = 0; double Max = 0; for(int i = 0; i < m; i++) if(Find(e[i].u) != Find(e[i].v)) { Merge(e[i].u, e[i].v); d[k++] = e[i].w; n--; if(n == 1) return; }}int main(){ int t, S, P, i, j; double x, y; scanf("%d",&t); while(t--) { m = 0; scanf("%d%d",&S,&P); Init(P); for(i = 1; i <= P; i++) scanf("%lf%lf",&p[i].x, &p[i].y); for(i = 1; i <= P; i++) for(j = i + 1; j <= P; j++) { e[m].u = i; e[m].v = j; e[m++].w = get_dis(p[i].x, p[i].y, p[j].x, p[j].y); e[m].u = j; e[m].v = i; e[m++].w = get_dis(p[i].x, p[i].y, p[j].x, p[j].y); } sort(e, e+m, comp); Kruskal(P); printf("%.2lf\n",d[P-S-1]); } return 0;}
阅读全文
0 0
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- poj 2349 Arctic Network
- poj 2349 Arctic Network
- POJ 2349 Arctic Network
- poj 2349 Arctic Network
- POJ-2349-Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- Poj 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ-2349 Arctic Network
- POJ 2349 Arctic Network
- POJ-2349-Arctic Network
- poj 2349 Arctic Network
- xxx is not in the sudoers file.This incident will be reported.的解决方法
- POJ 3552
- 三星A8000 ROM 刷机 root
- HDU 4913线段树好题
- STL Heap用法
- POJ 2349 Arctic Network
- Java中Queue和Deque的接口说明
- [Leetcode P17] Letter Combinations of a Phone Number(看作递增加法器)
- 树莓派网络与更新配置(有线、无线)
- 2017.08.04总结
- pymysql(一)检索、增加、更新、删除数据
- 树莓派常用软件及服务(vi、远程桌面、ssh、samba、u盘)
- 使用FileUtils简化你的文件操作
- scrollview嵌套listview的解决方法(一)