Eddy's picture

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6821    Accepted Submission(s): 3444

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
3
1.0 1.0
2.0 2.0
2.0 4.0
 
Sample Output
3.41
 
Author
eddy
 
此题数据规模娇小,prim随意处理即合..........
代码:
 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=;
double map[maxn][maxn];
double lowc[maxn];
bool vis[maxn];
struct point{ double x,y;
int id;
}; inline double dista(point a,point b){
return sqrt((a.y-b.y)*(a.y-b.y)+(a.x-b.x)*(a.x-b.x));
} point sac[maxn]; double prim(int st,int n)
{
memset(vis,,sizeof(vis));
vis[st]=true;
double minc=inf;
for(int i=;i<=n;i++)
lowc[i]=map[st][i];
int pre=st;
double sum=0.0;
for(int i=;i<n;i++){
minc=inf;
for(int j=;j<=n;j++)
{
if(!vis[j]&&minc>lowc[j]){
minc=lowc[j];
pre=j;
}
}
sum+=minc;
vis[pre]=true;
for(int j=;j<=n;j++){
if(!vis[j]&&lowc[j]>map[pre][j]){
lowc[j]=map[pre][j];
}
}
}
return sum;
}
void work(int n)
{
for(int i=;i<n;i++){
for(int j=;j<n;j++){
map[i+][j+]=map[j+][i+]=dista(sac[i],sac[j]);
}
}
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){ for(int i=;i<n;i++)
{
scanf("%lf%lf",&sac[i].x,&sac[i].y);
sac[i].id=i+;
}
work(n);
printf("%.2lf\n",prim(,n));
}
return ;
}

HDUOJ-----(1162)Eddy's picture(最小生成树)的更多相关文章

  1. hdu 1162 Eddy's picture(最小生成树算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...

  2. HDU 1162 Eddy's picture (最小生成树)(java版)

    Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...

  3. hdu 1162 Eddy's picture (最小生成树)

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  4. 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 ...

  5. hdoj 1162 Eddy's picture

    并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  6. HDU 1162 Eddy's picture

    坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32 ...

  7. hdu 1162 Eddy's picture (prim)

    Eddy's pictureTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. HDU 1162 Eddy's picture (最小生成树 prim)

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  9. HDU 1162 Eddy's picture (最小生成树 普里姆 )

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  10. hdu 1162 Eddy's picture(最小生成树,基础)

    题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...

随机推荐

  1. Cheatsheet: 2013 09.10 ~ 09.21

    .NET Lucene.Net – Custom Synonym Analyzer Using FiddlerCore to Capture Streaming Audio Immutable col ...

  2. How To PLAY_SOUND in Oracle Forms

    Play_sound is used to play audio files in Oracle Forms, Play_Sound plays the sound object in the spe ...

  3. VSFTP基线安全

    在企业级的应用中,越来越多的企业应用开源的vsftpd软件来搭建自己的文件共享服务,优点是速度快且节省开支.然而,企业用户行为难以预料,配置稍有不当则会使该服务成为一个安全风险点,导致带宽恶意占用.用 ...

  4. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. 小C的故事(快速学C语言,,,极速版!)

    前几天这篇博客写了太多废话! 删啦~~. 本篇博客只是为chd A协的全嫩小鲜肉入门C语言的预科, 如果你在此处学习C语言, 不幸走火入魔, 小弱概不负责. //请直接随便找个C语言编译器,抄一下下面 ...

  6. FlexSlider插件的详细设置参数 http://www.woothemes.com/flexslider/ -----幻灯片插件

    $(window).load(function() { $('.flexslider').flexslider({ namespace: 'flex-', //控件的命名空间,会影响样式前缀 anim ...

  7. mysql概要(十四)索引

    1.索引是对数据库数据建立目录加快了查询速度.索引分为哈希索引和二叉树索引 (大数据量转移,如果表中带有大量字段索引,进行数据导入时,建议先去掉索引导入数据再统一加入索引,减少索引计算量) 2.索引原 ...

  8. nodejs学习笔记<二>简单的node服务器

    在环境搭建好后,就可以开始动手架设(node驱动)一个简单的web服务器. 首先,nodejs还是用js编写.先来看一段node官网上的实例代码. var http = require('http') ...

  9. getAttribute()方法的使用小笔记

    今天在某课网上复习js,突然卡在一个小例子上.反复做了几遍就是报错.终于查询w3c才找到错误的源头. 这里记录一下,谨防以后又忘了. 错误码: <body> <p id=" ...

  10. Oracle 10g实现存储过程异步调用

    DBMS_JOB是什么?DBMS_JOB是Oracle数据库提供的专家程序包的一个.主要用来在后台运行程序,是数据库中一个极好的工具. 可用于自动调整调度例程任务,例如分析数据表,执行一些归档操作,清 ...