Eddy's picture(最小生成树)
Eddy's picture |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
Total Submission(s): 228 Accepted Submission(s): 168 |
Problem Description
Eddy begins to like painting pictures recently ,he is sure of himself to become a painter.Every day Eddy draws pictures in his small room, and he usually puts out his newest pictures to let his friends appreciate. but the result it 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
The first line contains 0 < n <= 100, the number of point. For each point, a line follows; each following line contains two real numbers indicating the (x,y) coordinates of the point.
Input contains multiple test cases. Process to the end of file. |
Output
Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the points.
|
Sample Input
|
Sample Output
|
Author
eddy
|
Recommend
JGShining
|
- #include<bits/stdc++.h>
- #define N 110
- using namespace std;
- struct node
- {
- int u,v;
- double val;
- node(){}
- node(int a,int b,double c)
- {
- u=a;
- v=b;
- val=c;
- }
- bool operator <(const node & a) const
- {
- return val<a.val;
- }
- };
- struct point
- {
- double x,y;
- point(){}
- point(double a,double b)
- {
- x=a;
- y=b;
- }
- };
- vector<node>edge;
- vector<point>p;
- int bin[N];
- double dis(point a,point b)
- {
- return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
- }
- int findx(int x)
- {
- while(bin[x]!=x)
- x=bin[x];
- return x;
- }
- int n;
- double x,y;
- void init()
- {
- for(int i=;i<=n;i++)
- bin[i]=i;
- }
- int main()
- {
- //freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
- while(scanf("%d",&n)!=EOF)
- {
- edge.clear();
- p.clear();
- init();
- for(int i=;i<n;i++)
- {
- scanf("%lf%lf",&x,&y);
- p.push_back(point(x,y));
- }
- for(int i=;i<p.size();i++)
- {
- for(int j=i+;j<p.size();j++)
- {
- edge.push_back(node(i,j,dis(p[i],p[j])));
- }
- }
- double cur=;
- sort(edge.begin(),edge.end());
- for(int i=;i<edge.size();i++)
- {
- int fx=findx(edge[i].u);
- int fy=findx(edge[i].v);
- if(fx!=fy)
- {
- cur+=edge[i].val;
- bin[fy]=fx;
- }
- }
- printf("%.2lf\n",cur);
- }
- return ;
- }
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 ...
- HDUOJ-----(1162)Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu Eddy's picture (最小生成树)
Eddy's picture Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- 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
坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32 ...
- Eddy's picture(prime+克鲁斯卡尔)
Eddy's picture Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- 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 ...
随机推荐
- 02.python基础知识_02
数据类型 1.整型 2.布尔值 3.字符串 4.列表 5.字典 6.集合 1.int(整型) i = 2 print(type(i)) 输出:<class 'int'> 2.bool(布尔 ...
- MMORPG战斗系统随笔(二)、浅谈场寻路Flow Field PathFinding算法
转载请标明出处http://www.cnblogs.com/zblade/ 今天给大家带来一篇游戏中寻路算法的博客.去年,我加入一款RTS的游戏项目,负责开发其中的战斗系统,战斗系统的相关知识,属于游 ...
- SSM框架——Spring+SpringMVC+Mybatis的搭建教程
一:概述 SSM框架在项目开发中经常使用到,相比于SSH框架,它在仅几年的开发中运用的更加广泛. Spring作为一个轻量级的框架,有很多的拓展功能,最主要的我们一般项目使用的就是IOC和AOP. S ...
- win32多线程编程
关于多线程多进程的学习,有没有好的书籍我接触的书里头关于多线程多进程部分,一是<操作系统原理>里面讲的相关概念 一个是<linux基础教程>里面讲的很简单的多线程多进程编程 ...
- js的严格模式详解
什么是js的严格模式? 严格模式指的是使js在更为严格的条件下运行.严格模式的主要作用是规范我们写代码习惯,以及为js升级做好铺垫. 如何使用严格模式? <script> //直接在代码 ...
- .NET第四章总结
.NET第四章简单总结 1.简单的获取文件路径: 2.回车跳转控件焦点 3.*************无标题窗体拖动!!************* 1): ...
- vue学习之指令简写以及事件笔记
1.v-bind:××× 可简写为 :××× 2.v-on:××× 可简写为 @××× 例: v-on:click 可简写为 @click (官网文档介绍) 3.vue处理事件 <!-- 阻止单 ...
- Linux查找和筛选工具
本文为原创文章,转载请标明出处 目录 文件名通配符 单字符匹配元字符 ? 多字符匹配元字符 * 字符范围匹配符 [] 排除范围匹配符 [!] 命令中的正则表达式 单字符匹配符 . 单字符或字符串重复匹 ...
- Python之scrapy实例1
下文参考:http://www.jb51.net/article/57183.htm 个人也是稍加整理,修改其中的一些错误,这些错误与scrapy版本选择有关,个环境:Win7x64_SP1 + Py ...
- 移动端效果之CellSwiper
写在前面 接着之前的移动端效果讲解,刚好项目中需要使用到这一效果,去饿了么的组件库看了一下效果,发现效果和微信端的cellSwiper还是有点差别的,由于项目中又是使用的React,之前使用的Reac ...