hdu 1162 Eddy's picture (Kruskal 算法)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1162
Eddy's picture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10085 Accepted Submission(s):
5094
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?
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.
places: the minimum total length of ink lines that can connect all the points.
- 19975116 2017-03-03 08:53:42 Accepted 1162 0MS 1524K 1304 B G++
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <algorithm>
- using namespace std;
- struct point
- {
- int x,y;
- double l;
- }p[];
- int parent[],n;
- double x[],y[];
- bool cmp(point a, point b)
- {
- return a.l < b.l;
- }
- int find(int x)
- {
- int s,tmp;
- for (s = x; parent[s] >= ; s = parent[s]);
- while (s != x)
- {
- tmp = parent[x];
- parent[x] = s;
- x = tmp;
- }
- return s;
- }
- void Union(int A, int B)
- {
- int a = find(A), b = find(B);
- int tmp = parent[a]+parent[b];
- if (parent[a] < parent[b])
- {
- parent[b] = a;
- parent[a] = tmp;
- }
- else
- {
- parent[a] = b;
- parent[b] = tmp;
- }
- }
- void kruskal(int k)
- {
- double sum = ;
- int u,v,i,j = ;
- memset(parent,-,sizeof(parent));
- for (i = ; i <= k; i ++)
- {
- u = p[i].x; v = p[i].y;
- if (find(u) != find(v))
- {
- sum += p[i].l;
- Union(u,v);
- j ++;
- }
- if (j == n-) break;
- }
- printf("%.2lf\n",sum);
- }
- int main ()
- {
- int i,j,k;
- while (scanf("%d",&n)!=EOF)
- {
- k = -;
- for (i = ; i <= n; i ++)
- scanf("%lf%lf",x+i,y+i);
- for (i = ; i < n; i ++)
- for (j = +i; j <= n; j ++)
- {
- p[++ k].x = i;
- p[k].y = j;
- p[k].l = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
- }
- sort(p,p+k+,cmp);
- kruskal(k);
- }
- return ;
- }
hdu 1162 Eddy's picture (Kruskal 算法)的更多相关文章
- 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个点 ...
- 题解报告:hdu 1162 Eddy's picture
Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...
- 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 (最小生成树)
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 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 ...
随机推荐
- HNOI2018 退役记
HNOI2018 退役记 \(day0\): 除了切水题以外没有什么很重要的事. \(day1\): 进考场发现前面是\(yyb\)?\(orzyyb\) 试题解压密码终于没有奇怪的字符了,一遍打对. ...
- crontab例行性共作
一.单一工作调度 at [-mldv] TIME at -c 工作号码 -m:当at工作结束后,即是没有输出信息,以email通知用户该工作已完成 -l:at -l相当于atq,列出目前系统上所有的a ...
- ABP与多租户
ABP简介 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称. ASP.NET Boilerplate是一个用最佳实践和流行技术开发现代WEB应用程 ...
- 【python】-matplotlib.pylab常规用法
目的: 了解matplotlib.pylab常规用法 示例 import matplotlib.pylab as pl x = range(10) y = [i * i for i in x] pl. ...
- 高并发和多线程——Java内存模型
个人理解: 1.并发编程分为三个核心:分工.同步.互斥 2.CPU.内存.I/O存在速度差异问题. 3.线程切换导致原子性问题.编译优化导致有序性问题.缓存导致可见性问题. 4.Java内存模型规范了 ...
- openstf安装手记
一款基于nodejs+jade模板开发的手机群控框架,你可以在此基础上拿来测试设备,或者群操作等等. 主要核心技术在于如何在不root的情况下实时流畅录屏,以及远程操作手机. 官方git https: ...
- selenium自动化测试用例需要关注的几点(二)
注:原文地址 UI映射 一个UI映射是一种机制,它存储所有的定位器的测试套件在一个地方,方便修改UI元素的路径标识符或改变在AUT.测试脚本,然后使用UI地图定位以被测试的元件.基本上,UI地图是一个 ...
- HTML5离线资源缓存简介
cache manifest 示例 要使用离线资源缓存,开发者首先要提供一个 cache manifest 文件 它列出了所有需要在离线状态下使用的资源,浏览器会把这些资源缓存到本地 下面就是一个 c ...
- OpenGL初识
OpenGL 概念 OpenGL提供的是一系列接口, 它是指一个规范, OpenGL规范严格规定了每个函数该如何执行, 以及它们的输出值, 具体的实现是由各个显示设备厂商, 它作为本地系统库直接运行在 ...
- Java入门系列-20-异常
为什么要进行异常处理 下面这段代码能否正常执行 public class DemoCalc { public static void main(String[] args) { int a=0; in ...