UvaOJ10369 - Arctic Network
- /*
- The first line of each test case contains 1 <= S <= 100, the number of satellite channels!
- 注意:S表示一共有多少个卫星,那么就是有 最多有S-1个通道! 然后将最小生成树中的后边的 S-1通道去掉就行了!
- 思路:最小生成树中的第 k 个最小边!
- */
- //克鲁斯克尔算法.....
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<cmath>
- using namespace std;
- double x[], y[];
- struct node{
- int u, v;
- double d;
- };
- bool cmp(node a, node b){
- return a.d < b.d;
- }
- int f[];
- node nd[];
- double ret[];
- int getFather(int x){
- return x==f[x] ? x : f[x]=getFather(f[x]);
- }
- bool Union(int a, int b){
- int fa=getFather(a), fb=getFather(b);
- if(fa!=fb){
- f[fa]=fb;
- return true;
- }
- return false;
- }
- int main(){
- int n, m;
- int t;
- scanf("%d", &t);
- while(t--){
- scanf("%d%d", &m, &n);
- for(int i=; i<=n; ++i){
- scanf("%lf%lf", &x[i], &y[i]);
- f[i]=i;
- }
- int cnt=;
- for(int i=; i<n; ++i)
- for(int j=i+; j<=n; ++j){
- nd[cnt].u=i;
- nd[cnt].v=j;
- nd[cnt++].d=sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
- }
- sort(nd, nd+cnt, cmp);
- int cc=;
- for(int i=; i<cnt; ++i)
- if(Union(nd[i].u, nd[i].v))
- ret[cc++]=nd[i].d;
- for(int i=; i<cc; ++i)
- cout<<ret[i]<<"fdsf"<<endl;
- printf("%.2lf\n", ret[n-m-]);
- }
- return ;
- }
- //prim算法.......
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<cmath>
- using namespace std;
- const double INF = 0x3f3f3f3f*1.0;
- double x[], y[];
- int n, m;
- double map[][];
- int vis[];
- double ret[];
- void prim(){
- memset(vis, , sizeof(vis));
- vis[]=;
- for(int i=; i<=n; ++i)
- ret[i]=INF;
- int root=, p;
- for(int i=; i<n; ++i){
- double minLen=INF;
- for(int j=; j<=n; ++j){
- if(!vis[j] && ret[j]>map[root][j])
- ret[j]=map[root][j];
- if(!vis[j] && minLen>ret[j]){
- minLen=ret[j];
- p=j;
- }
- }
- root=p;
- vis[root]=;
- }
- }
- int main(){
- int t;
- scanf("%d", &t);
- while(t--){
- scanf("%d%d", &m, &n);
- for(int i=; i<=n; ++i)
- scanf("%lf%lf", &x[i], &y[i]);
- for(int i=; i<n; ++i)
- for(int j=i+; j<=n; ++j)
- map[i][j]=map[j][i]=sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
- prim();
- sort(ret, ret+n+);
- printf("%.2lf\n", ret[n-m+]);
- }
- return ;
- }
UvaOJ10369 - Arctic Network的更多相关文章
- [poj2349]Arctic Network(最小生成树+贪心)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17758 Accepted: 5646 D ...
- Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9557 Accepted: 3187 De ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- poj 2349 Arctic Network
http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- POJ2349 Arctic Network 2017-04-13 20:44 40人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19113 Accepted: 6023 D ...
- POJ2349:Arctic Network(二分+最小生成树)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28311 Accepted: 8570 题 ...
- POJ2349 Arctic Network(Prim)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16968 Accepted: 5412 D ...
- POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru
Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...
随机推荐
- android studio打包出现翻译问题
错误信息: Error:(16) Error: "baidutieba_client_inavailable" is not translated in "en" ...
- Python学习之路--select解析
sellect.poll.epoll三者的区别 select select最早于1983年出现在4.2BSD中,它通过一个select()系统调用来监视多个文件描述符的数组,当select()返回后, ...
- mono for android 各版本下载地址
window下 在XamarinStudio 检查更新,会在这个目录下生成LOG和下载文件,所以可以从里面复制出来,查看真实下载地址 C:\Users\用户名\AppData\Local\Xamari ...
- spi接口的ds1302时钟芯片控制在lcd1602上显示
spi接口的ds1302时钟芯片控制在lcd1602上显示 ...
- AWIT DBackup 0.0.20 发布,备份系统
AWIT DBackup 0.0.20 修复了几个小 bug. AllWorldIT DBackup 是一个备份系统,为每个目录创建一个独立的压缩包,这更便于搜索. 特点: 使用 xz, bzip2, ...
- C#实现 word、pdf、ppt 转为图片
office word文档.pdf文档.powerpoint幻灯片是非常常用的文档类型,在现实中经常有需求需要将它们转换成图片 -- 即将word.pdf.ppt文档的每一页转换成一张对应的图片,就像 ...
- Sensor(PROXIMITY)
package com.example.sensor01; import android.hardware.Sensor; import android.hardware.SensorEvent; i ...
- Sensor(ACCELEROMETER)
package com.example.sensor01; import java.util.List; import android.hardware.Sensor; import android. ...
- 【面试必备】javascript的原型和继承
原型.闭包.作用域等知识可以说是js中面试必考的东西,通过你理解的深度也就能衡量出你基本功是否扎实.今天来复习一下javascript的原型和继承,虽说是老生常谈的话题,但对于这些知识,自己亲手写一遍 ...
- fsfds
ccc fs -fsd fsdfsfs