POJ2349(求生成树中符合题意的边)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 14977 | Accepted: 4777 |
Description
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
Output
Sample Input
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
题意及思路:有P个坐标,将P个坐标分为S组,求所有组的生成树的最大边中的最大边。求P个坐标构成的生成树,将边由大到小排序,第S条边即为所求。
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=*;
const double INF=1.0e8;
typedef pair<double,int> P;
struct Point{
int x,y,index;
}points[];
struct Edge{
int to,next;
double cost;
}es[MAXN];
int V,E;
double dist(int x1,int y1,int x2,int y2)
{
return sqrt((double)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
bool comp(double a,double b)
{
return a > b;
}
int head[];
void add_edge(int u,int v,double cost)
{
es[E].to=v;
es[E].cost=cost;
es[E].next=head[u];
head[u]=E;
E++;
}
int cnt;
double res[];
double d[];
int vis[];
void prim(int s)
{
for(int i=;i<=V;i++)
{
d[i]=INF;
vis[i]=;
}
d[s]=;
cnt=;
priority_queue<P,vector<P>,greater<P> > que;
que.push(P(,s));
while(!que.empty())
{
P now=que.top();que.pop();
int v=now.second;
if(vis[v]) continue;
res[cnt++]=now.first;
vis[v]=;
for(int i=head[v];i!=-;i=es[i].next)
{
Edge e=es[i];
if(d[e.to]>e.cost)
{
d[e.to]=e.cost;
que.push(P(d[e.to],e.to));
}
}
}
} int main()
{
int T;
scanf("%d",&T);
int S,P;
while(T--)
{
scanf("%d%d",&S,&P);
memset(head,-,sizeof(head));
V=P;
E=;
for(int i=;i<P;i++)
{
scanf("%d%d",&points[i].x,&points[i].y);
points[i].index=i+;
}
for(int i=;i<P;i++)
for(int j=i+;j<P;j++)
{
int indi=points[i].index;
int indj=points[j].index;
double co=dist(points[i].x,points[i].y,points[j].x,points[j].y);
add_edge(indi,indj,co);
add_edge(indj,indi,co);
} prim();
sort(res,res+cnt,comp);
printf("%0.2lf\n",res[S-]);
} return ;
}
POJ2349(求生成树中符合题意的边)的更多相关文章
- poj3532求生成树中最大权与最小权只差最小的生成树+hoj1598俩个点之间的最大权与最小权只差最小的路经。
该题是最小生成树问题变通活用,表示自己开始没有想到该算法:先将所有边按权重排序,然后枚举最小边,求最小生成树(一个简单图的最小生成树的最大权是所有生成树中最大权最小的,这个容易理解,所以每次取最小边, ...
- exp导出一个表中符合查询条件的数据
原文地址:exp导出一个表中符合查询条件的数据 作者:charsi 导出一个表中的部分数据,使用QUERY参数,如下导出select * from test where object_id>50 ...
- js 数组 添加或删除 元素 splice 创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素 filter
里面可以用 箭头函数 splice 删除 增加 数组 中元素 操作数组 filter 创建新数组 检查指定数组中符合条件的所有元素
- 【转载】 C#中使用Count方法获取List集合中符合条件的个数
很多时候操作List集合的过程中,我们需要根据特定的查询条件,获取List集合中有多少个实体对象符合查询条件,例如一批产品的对象List集合,如果这批产品的不合格数量大于10则重点备注.在C#中可以自 ...
- 【转载】C#使用FirstOrDefault方法快速查找List集合中符合条件的第一个实体
在C#的List集合的操作中,有时候我们需要根据相关条件快速从List集合中获取到第一个符合条件的实体对象,例如有个全校班级的List集合,我们需要根据班级代码快速从List集合中查找出班级信息.可以 ...
- 【Matlab开发】matlab删除数组中符合条件的元素与散点图绘制
[Matlab开发]matlab删除数组中符合条件的元素与散点图绘制 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ matlab删除数组中符合条件的元素 如 ...
- Makefile 中符合的使用
1. $@: 表示规则中的目标文件集.在模式规则中,如果有多个目标,那么,"$@"就是匹配于 目标中模式定义的集合 2. $^ : 所有的依赖目标的集合.以空格分隔.如果在依赖目 ...
- PHP使用array_filter查找二维数组中符合字段和字段值的数据集合
1.方法: /** * 获取符合字段和字段值的数组集合 * @param array $data 待过滤数组 * @param string $field 要查找的字段 * @param $value ...
- POJ-2485 Highways---最小生成树中最大边
题目链接: https://vjudge.net/problem/POJ-2485 题目大意: 求最小生成树中的最大边 思路: 是稠密图,用prim更好,但是规模不大,kruskal也可以过 #inc ...
随机推荐
- 输入一个n,输出2到n的详细素数值
#include<stdio.h> #include<algorithm> #include<cmath> int judge(int a) { int j; fo ...
- 漫反射和Lambert模型
粗糙的物体表面向各个方向等强度地反射光,这种等同地向各个方向散射的现象称为光的漫反射(diffuse reflection).产生光的漫反射现象的物体表面称为理想漫反射体,也称为朗伯(Lambert) ...
- Unity3D研究院编辑器之重写Hierarchy的右键菜单
Hierarchy视图中选择一个游戏对象以后通过右键可以打开一个unity默认菜单,一般情况下都可以满足我们,但是我想真对某些特殊的游戏对象而展开特殊的菜单.如下图所示,比如这样: 代码: using ...
- iOS7 文本转语音 AVSpeechSynthesizer -转载-
http://www.cnblogs.com/qingjoin/p/3160945.html iOS7 的这个功能确实不错.我刚试了下,用官方提供的API ,简单的几句代码就能实现文本转语音! Xco ...
- EasyPlayer_Android RTSP安卓播放器直播画面卡在第一帧问题修复
最近发现某些Android安卓手机在运行EasyPlayer播放视频时,会停留在第一帧画面,虽然有码率预示着接收端没有问题,但是画面却卡着不动. 一般来讲,这个现象有三种原因导致: 没有接收到视频帧; ...
- Vue 填坑系列(持续更新...)
1.遇到页面显示不更新,数据已更新情况 vue-cli中: this.$nextTick(function () { this.x=x; }) 以js引入vue的网页中: this.$set( ...
- ajax工作原理(转)
在写这篇文章之前,曾经写过一篇关于AJAX技术的随笔,不过涉及到的方面很窄,对AJAX技术的背景.原理.优缺点等各个方面都很少涉及null.这次写这篇文章的背景是因为公司需要对内部程序员做一个培训.项 ...
- 远程服务器上的weblogic项目管理(五) PermGen内存溢出问题
weblogic偶尔会出现PermGen异常,内存溢出的问题,这个时候需要修改weblogic安装目录下的domain/common/bin/commEnv.cmd. 打开后在其中找到: set ME ...
- Spring-data-redis:特性与实例(转载)
原文地址:http://www.cnblogs.com/davidwang456/p/4915109.html Spring-data-redis为spring-data模块中对redis的支持部分, ...
- Java for LeetCode 104 Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...