hdu Eddy's picture (最小生成树)
Eddy's picture
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 29 Accepted Submission(s) : 26
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Problem descriptions as follows: Given you some coordinates pionts on a drawing paper, every point links with the ink with the straight line, causes all points finally to link in the same place. How many distants does your duty discover the shortest length which the ink draws?
Input
Input contains multiple test cases. Process to the end of file.
Output
Sample Input
3
1.0 1.0
2.0 2.0
2.0 4.0
Sample Output
3.41
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
using namespace std;
const int maxn=;
double mp[maxn][maxn];
double dis[maxn],x[maxn],y[maxn];
int vis[maxn];
int i,j,n,l,k;
double minn,sum; int main()
{
while(~scanf("%d",&n))
{
memset(vis,,sizeof(vis));
for(i=;i<=n;i++) scanf("%lf%lf",&x[i],&y[i]);
for(i=;i<=n;i++)
for(j=i+;j<=n;j++)
{
double d=sqrt(pow(x[i]-x[j],)+pow(y[i]-y[j],));
mp[i][j]=d;
mp[j][i]=d;
}
sum=;
vis[]=;
for(i=;i<=n;i++) dis[i]=mp[][i];
for(i=;i<n;i++)
{
minn=INT_MAX*1.0;
for(j=;j<=n;j++)
if(!vis[j] && minn>dis[j])
{
k=j;
minn=dis[j];
}
vis[k]=;
sum+=minn;
for(j=;j<=n;j++)
if (!vis[j] && dis[j]>mp[k][j])
dis[j]=mp[k][j];
}
printf("%.2lf\n",sum);
}
return ;
}
hdu Eddy's picture (最小生成树)的更多相关文章
- HDU 1162 Eddy's picture (最小生成树)(java版)
Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...
- hdu 1162 Eddy's picture (最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1162 Eddy's picture(最小生成树算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- hdu 1162 Eddy's picture (Kruskal 算法)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- HDUOJ-----(1162)Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1162 Eddy's picture
坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32 ...
- Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- hdu 1162 Eddy's picture (prim)
Eddy's pictureTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdoj 1162 Eddy's picture
并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
随机推荐
- $addToSet $push
结果:
- 洛谷-语文成绩-[有奖]洛谷5月月赛:kkksc03的三大神器
题目背景 Background语文考试结束了,成绩还是一如既往地有问题. 题目描述 Description语文老师总是写错成绩,所以当她修改成绩的时候,总是累得不行.她总是要一遍遍地给某些同学增加分数 ...
- 用mybatis生成插件自动生成配置文件
1.在当前的maven项目的pom.xml中添加插件 <build> <plugins> <plugin> <groupId>org.mybatis.g ...
- C - 娜娜梦游仙境系列——吃不完的糖果
C - 娜娜梦游仙境系列——吃不完的糖果 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Oth ...
- 模拟IIC协议时序
IIC是飞利浦公司开发的两线式串行总线,主要应用在单片机和外围电子器件之间的数据通讯. IIC总线优点是节约总线数,稳定,快速,是目前芯片制造上非常流行的一种总线,大多数单片机已经片内集成了IIC总线 ...
- 判断pc浏览器和手机浏览器方法
一 //平台.设备和操作系统 var system = { win: false, mac: false, xll: f ...
- 转载 Deep learning:二(linear regression练习)
前言 本文是多元线性回归的练习,这里练习的是最简单的二元线性回归,参考斯坦福大学的教学网http://openclassroom.stanford.edu/MainFolder/DocumentPag ...
- 9509 开灯(dfs)
9509 开灯 时间限制:1000MS 内存限制:65535K提交次数:0 通过次数:0 题型: 编程题 语言: G++;GCC Description 有16的开关分别控制16盏灯,开关排列成 ...
- C# 获取字符的Unicode编码
using UnityEngine;using System.Collections;using System.Collections.Generic; List<); string chars ...
- VBS 自动发送邮件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...