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 ...
随机推荐
- request 防盗链
package request; import java.io.IOException;import javax.servlet.ServletException;import javax.servl ...
- mybatis的拦截器及分页机制
https://blog.csdn.net/ssuperlg/article/details/79847889
- 世界更清晰,搜狐新闻客户端集成HUAWEI HiAI 亮相荣耀Play发布会!
6月6日,搭载有“很吓人”技术的荣耀Play正式发布,来自各个领域的大咖纷纷为新机搭载的惊艳技术站台打call,其中,搜狐公司董事局主席兼首席执行官张朝阳揭秘:华为和搜狐新闻客户端在硬件AI方面做 ...
- 巧用Excel提高工作效率
程序员如何巧用Excel提高工作效率 主要讲解下Excel中VLOOKUP函数的使用,相比于上一篇中的内容,个人觉得这个相对高级一些. 1.使用背景 为什么会使用到这个函数呢,背景是这样的,有两个系统 ...
- 使用active mq
1 windows下使用active mq 1.1 下载active mq 1.2 点击根目录\bin\win64\activemq.bat运行 1.3 登陆查看 http://localhost:8 ...
- SAP数据表相关
[转]SAP 数据表相关信息 今天用到了根据字段取数据元素描述,以前做过忘啦,在谢兄的帮助下搞定,把他的总结粘出来记住. 存储域(Domain)信息的表为DD01L:存储数据元素(Data Eleme ...
- Android databinding 开发参考
1,android studio添加databinding依赖需要注意事项: http://www.zhihu.com/question/33538477?sort=created 2, databi ...
- 《高性能Javascript》 Summary(一)
第一章.加载和执行 Loading & Execution 原因:Javascript 的执行导致页面渲染中止等待. 解决: 将script放在页面底部,紧靠body 闭合标签之前,保证页面在 ...
- 4.1 《锋利的jQuery》jQuery中的事件
$(document).ready()方法和window.onload方法的区别 事件绑定 合成事件 事件冒泡 事件对象的属性 tip1:停止事件冒泡和阻止默认行为都可以用return false替代 ...
- WebsiteCrawler
看到网上不少py的爬虫功能极强大,可惜对py了解的不多,以前尝试过使用c# WebHttpRequert类来读取网站的html页面源码,然后通过正则表达式筛选出想要的结果,但现在的网站中,多数使用js ...