hdoj--1162--Eddy's picture(最小生成树)
Eddy's picture
can be imagined, the friends are not interested in his picture.Eddy feels very puzzled,in order to change all friends 's view to his technical of painting pictures ,so Eddy creates a problem for the his friends of you.
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 contains multiple test cases. Process to the end of file.
3 1.0 1.0 2.0 2.0 2.0 4.0
3.41
- #include<stdio.h>
- #include<math.h>
- #include<string.h>
- #include<algorithm>
- using namespace std;
- struct node
- {
- int x,y;
- double val;
- }edge[100100];
- double x[10010],y[10010];
- int cmp(node s1,node s2)
- {
- if(s1.val<s2.val)
- return 1;
- return 0;
- }
- int pre[10010];
- void init()
- {
- for(int i=0;i<10010;i++)
- pre[i]=i;
- }
- int find(int x)
- {
- return pre[x]==x?x:pre[x]=find(pre[x]);
- }
- int main()
- {
- int n;
- while(scanf("%d",&n)!=EOF)
- {
- for(int i=0;i<n;i++)
- scanf("%lf%lf",&x[i],&y[i]);
- int cnt=0;
- init();
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<n;j++)
- {
- if(i==j) continue;
- edge[cnt].x=i;
- edge[cnt].y=j;
- edge[cnt++].val=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
- }
- }
- sort(edge,edge+cnt,cmp);
- double sum=0;
- for(int i=0;i<cnt;i++)
- {
- int fx=find(edge[i].x);
- int fy=find(edge[i].y);
- if(fx!=fy)
- {
- sum+=edge[i].val;
- pre[fx]=fy;
- }
- }
- printf("%.2lf\n",sum);
- }
- return 0;
- }
hdoj--1162--Eddy's picture(最小生成树)的更多相关文章
- 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 (最小生成树)(java版)
Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...
- hdoj 1162 Eddy's picture
并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 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 (Kruskal 算法)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 1162 Eddy's picture
坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32 ...
- hdu 1162 Eddy's picture (prim)
Eddy's pictureTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1162 Eddy's picture (最小生成树 prim)
题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...
- HDU 1162 Eddy's picture (最小生成树 普里姆 )
题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...
- hdu 1162 Eddy's picture(最小生成树,基础)
题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...
随机推荐
- linux编译安装protobuf2.5.0
1.下载安装包 https://github.com/google/protobuf/releases?after=v3.0.0-alpha-4.1 找到相应的版本下载 2.解压安装包 #.tar.g ...
- window下svn开机自动启动
- 织梦dedecms红黑配图片模板源码v2.0
dedecms红黑配风格美女图片站是采用dedecms程序搭建的图片网站源码,网站感觉很大气,简约但是不简单,适合做图片网站.网站模板是收集其他网站的模板,感谢原网站提供者.在安装过程中出现问题,现已 ...
- AngularJs轻松入门
AngularJs轻松入门系列博文:http://blog.csdn.net/column/details/angular.html AngularJs轻松入门(一)创建第一个应用 AngularJs ...
- Android ExpandableListView group的item有间距child间隔不变
<ExpandableListView android:id="@+id/lv" android:layout_width="fill_parent" a ...
- hdu2112 HDU Today 基础最短路
这题的关键是把车站的名字转化为点的编号.我用的是map.声明一个map<string,int> st,然后按照字符串出现的次序给st赋值.例如:st[s1]=2;代表这字符串s1出现的次序 ...
- 获取 Windows Phone 的 User-Agent 字符串
这个是简单介绍一下如何在wp开发中获取 Windows Phone 的 User-Agent 字符串,更多wp移动开发就去那个wp教程网吧.http://wp.662p.com 使用方法 public ...
- 函数反抖 debounce
debounce :如果在一段延时内又触发了事件,则重新开始延时.即每次触发事件,只触发最近一次的事件. const debounce = (fn, duration) => { let tim ...
- paramiko模块学习笔记
SSHClient 基于用户名密码连接 import paramiko # 创建SSH对象 ssh = paramiko.SSHClient() # 允许连接不在know_hosts文件中的主机 ss ...
- python网络编程part1
1. 网络架构 单机 单机游戏 以下两个基于网络的 CS架构 客户端游戏 cs--->client客户/server服务 你自己是客户端(消费)--->服务端(收钱) 服务端(应用程序)一 ...