poj2349Arctic Network最小生成树
来源:互联网 发布:淘宝如何退保证金 编辑:程序博客网 时间:2024/05/18 07:25
开始是读错题,其实题意只是要顾及临边,即每次加入到集合的那个数本身,排个序就好了==可是为什么cin 改成scanf就不对==
还有就是c++中格式输出的写法== 刚考完就忘了 T^T还好意思嘚瑟自己成绩吗 --->_--->
vjudge上的中文叙述
Description
国防部(DND)要用无线网络连接北部几个哨所。两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫星频道。
任何两个有卫星信道的哨所可以通过卫星进行通信,而不管他们的位置。同时,当两个哨所之间的距离不超过D时可以通过无线电通讯,D取决于对收发器的功率。功率越大,D也越大,但成本更高。出于采购和维修的方便,所有哨所的收发器必须是相同的;那就是说,D值对每一个哨所相同。
你的任务是确定收发器的D的最小值。每对哨所间至少要有一条通信线路(直接或间接)。
Input
输入的第一行是测试数据的数量N。
每组测试数据的第一行包含卫星频道的数量S(1 < = S < = 100)和哨所的数量P(S < P < = 500)。接下来的P行,给出以公里为单位的每个哨所的坐标(x,y)(坐标为0到10000之间的整数)。
Output
对于每组测试数据,输出一行,输出收发器的D的最小值。精确到小数点后两位。
Sample Input
12 40 1000 3000 600150 750
Sample Output
212.13
Description
The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver and some outposts will in addition have a satellite channel.
Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.
Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.
Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.
Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.
Input
The first line of input contains N, the number of test cases. The first line of each test case contains 1 <= S <= 100, the number of satellite channels, and S < P <= 500, the number of outposts. P lines follow, giving the (x,y) coordinates of each outpost in km (coordinates are integers between 0 and 10,000).
Output
For each case, output should consist of a single line giving the minimum D required to connect the network. Output should be specified to 2 decimal points.
Sample Input
12 40 1000 3000 600150 750
Sample Output
212.13
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int flag1=0;int n,s,p;double sum;double arr_list[504][504];double d[503];struct Edge{ int point; double lowcost; int flag;};Edge edge[505];bool cmp(double a,double b){ return a>b;}struct Point{ double x,y;}point[502];void prim(int p){ int i,j,k=1; double min,sum2=0; j=1; for(i=1;i<=p;i++) { if(i!=j) { edge[i].point=j; edge[i].lowcost=arr_list[j][i]; edge[i].flag=0; } } edge[j].lowcost=0; edge[j].flag=1; int l=0; for(i=1;i<p;i++) { min=65535000; for(j=2;j<=p;j++) { if(edge[j].flag==0&&edge[j].lowcost<min) { k=j; min=edge[j].lowcost; } } d[l++]=arr_list[k][edge[k].point]; //sum2+=min; edge[k].flag=1; for(j=2;j<=p;j++) { if(edge[j].flag==0&&arr_list[k][j]<edge[j].lowcost) { edge[j].point=k; edge[j].lowcost=arr_list[k][j]; } } }}int main(){ // freopen("cin.txt","r",stdin); cin>>n; while(n--) { cin>>s>>p; for(int i=1;i<=p;i++) { cin>>point[i].x>>point[i].y; arr_list[i][i]=65535000; } for(int i=1;i<p;i++) { for(int j=i+1;j<=p;j++) { arr_list[i][j]=sqrt(pow((point[i].x-point[j].x),2)+pow((point[i].y-point[j].y),2)); arr_list[j][i]=arr_list[i][j]; //cout<<arr_list[i][j]<<endl; } } prim(p); sort(d,d+p-1,cmp); cout.setf(ios::fixed);//保留两位小数 cout.precision(2); cout<<d[s-1]<<endl; } return 0;}
0 0
- poj2349Arctic Network最小生成树
- POJ2349Arctic Network(最小生成树)
- poj2349Arctic Network (最小生成树运用)
- POJ2349Arctic Network之最小生成树kruskal解法
- poj2349Arctic Network(最小生成树kruscal+第k长的边)
- poj1861--Network(最小生成树)
- POJ_2349_Arctic Network(最小生成树)
- POJ1861 Network(最小生成树)
- POJ 2349 Arctic Network [最小生成树]
- poj 1861Network(最小生成树)
- POJ 1861 Network 最小生成树
- uva 10369 - Arctic Network(最小生成树)
- poj 2349 (最小生成树)Arctic Network
- POJ 1861 Network ---最小生成树
- URAL - 1160 Network(最小生成树)
- URAL 1160. Network 最小生成树
- poj 1861 Network (kruskal 最小生成树)
- UVA 10369 - Arctic Network(最小生成树)
- php学习整理之linux(vi编辑器操作指令)
- java 块的研究
- 解决电信只能在唯一的电脑上拨号上网的问题(MAC克隆)
- 黑马程序员——JAVA笔记——IO操作
- 双向冒泡排序
- poj2349Arctic Network最小生成树
- myeclipse&eclipse配置tomcat端口、配置从根目录访问web项目
- 圈排序
- 重温HBaes部署与java客户端访问
- ORA-00918 column ambiguously defined
- 自我简绍
- C++中生成任意范围内随机数的方法
- java中自带的对于自定义的类的排序
- 选择排序