HDU 1875 畅通工程再续(kruskal)
畅通工程再续
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 22650 Accepted Submission(s): 7231
每组数据首先是一个整数C(C <= 100),代表小岛的个数,接下来是C组坐标,代表每个小岛的坐标,这些坐标都是 0 <= x, y <= 1000的整数。
2
2
10 10
20 20
3
1 1
2 2
1000 1000#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h> using namespace std;
struct Node
{
int x;
int y;
double w;
}a[100*100+5];
int father[105];
int n;
int find(int x)
{
if(x!=father[x])
father[x]=find(father[x]);
return father[x];
}
int b[105];
int c[105];
int cmp(Node a,Node b)
{
return a.w<b.w;
}
double judge(int x,int y)
{
double len=sqrt(1.0*(b[x]-b[y])*(b[x]-b[y])+1.0*(c[x]-c[y])*(c[x]-c[y]));
if(len>=10&&len<=1000)
return len;
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&b[i],&c[i]);
}
int cot=0;
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
double len=judge(i,j);
if(judge(i,j))
{
a[cot].x=i;
a[cot].y=j;
a[cot++].w=len*100;
}
}
}
sort(a,a+cot,cmp);
for(int i=1;i<=n;i++)
father[i]=i;
double ans=0;
for(int i=0;i<cot;i++)
{
int xx=find(a[i].x);
int yy=find(a[i].y);
if(xx!=yy)
{
ans+=a[i].w;
father[xx]=yy;
}
}
int tag=0;
for(int i=1;i<=n;i++)
{
find(i);
if(father[i]==i)
tag++;
}
if(tag>=2)
printf("oh!\n");
else
printf("%.1f\n",ans);
}
return 0; }
HDU 1875 畅通工程再续(kruskal)的更多相关文章
- HDU 1875 畅通工程再续 (prim最小生成树)
B - 畅通工程再续 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- hdu 1875 畅通工程再续(prim方法求得最小生成树)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1875 /************************************************* ...
- HDU 1875 畅通工程再续 (最小生成树)
畅通工程再续 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDU 1875 畅通工程再续 (最小生成树)
畅通工程再续 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/M Description 相信大家都听说一个"百岛湖&q ...
- HDU 1875 畅通工程再续 (Prim)
题目链接:HDU 1875 Problem Description 相信大家都听说一个"百岛湖"的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现 ...
- HDU - 1875 畅通工程再续【最小生成树】
Problem Description 相信大家都听说一个"百岛湖"的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖 ...
- HDU - 1875 畅通工程再续
Problem Description 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问 ...
- hdu 1875 畅通工程再续(最小生成树,基础)
题目 让人郁闷的题目,wa到死了,必须要把判断10.0和1000.0的条件放到prim函数外面去.如代码所放.... 正确的(放在prim外): //2个小岛之间的距离不能小于10米,也不能大于100 ...
- (step6.1.3)hdu 1875(畅通工程再续——最小生成树)
题目大意:本题是中文题,可以直接在OJ上看 解题思路:最小生成树 1)本题的关键在于把二维的点转化成一维的点 for (i = 0; i < n; ++i) { scanf("%d%d ...
随机推荐
- Actors编程模型
Actors模型(Actor model)首先是由Carl Hewitt在1973定义, 由Erlang OTP (Open Telecom Platform) 推广,其 消息传递更加符合面向对象的原 ...
- MongoDB - 内嵌角色
数据库用户角色(每个数据库都有的角色) 角色名 说明 read 对non-system集合的读取权限,以及以下system集合的读取权限:system.indexes,system.js,syst ...
- Windows下Python添加MySQLdb扩展模块
[更新 2012-09-16] 这里可以下载已经打包好的EXE文件,http://sourceforge.net/projects/mysql-python/(国内需穿越才可访问) DBank备份下载 ...
- 基于numpy的随机数构造
class numpy.random.RandomState(seed=None) RandomState 是一个基于Mersenne Twister算法的伪随机数生成类 RandomState 包含 ...
- Redis 的 fields 遇到的问题
问题描述:本地和测试环境同使用一台redis服务器,本地环境和测试环境使用 key,fileds,value 中的fileds 来区分,例如 key fields value 004920c6eba1 ...
- Jquery学习笔记(2)--五角星评分
网购五星评分模拟: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- spring-core依赖jar包
- javascript属性详解
在js中,没有公共属性和私有属性之分,只有全局变量(全局属性)和局部变量以及对象属性.但是,程序员可以通过一定的技巧来实现面向对象语言的功能.下面我们来介绍这几种属性(变量) 全局变量也叫全局属性 / ...
- Using a long as ArrayList index in java
http://stackoverflow.com/questions/459643/using-a-long-as-arraylist-index-in-java http://bbs.csdn.ne ...
- checkbox 更新回显
if($row['name']==$_SESSION['name']){$checked="checked disabled";}else{$checked=" &quo ...