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&#39;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&#39;s picture (最小生成树)(java版)

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

  3. hdu 1162 Eddy&#39;s picture (最小生成树)

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

  4. hdu 1162 Eddy&#39;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&#39;s picture

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

  6. HDU 1162 Eddy&#39;s picture

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

  7. hdu 1162 Eddy&#39;s picture (prim)

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

  8. HDU 1162 Eddy&#39;s picture (最小生成树 prim)

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

  9. HDU 1162 Eddy&#39;s picture (最小生成树 普里姆 )

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

  10. hdu&#160;1162&#160;Eddy&#39;s&#160;picture(最小生成树,基础)

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

随机推荐

  1. 深入node之Transform

    Transform流特性 在开发中直接接触Transform流的情况不是很多,往往是使用相对成熟的模块或者封装的API来完成流的处理,最为特殊的莫过于through2模块和gulp流操作.那么,Tra ...

  2. Spring 的动态数据源实现

    1. 配置多个数据源 这里以两个c3p0数据库连接池的数据源作为实例.在Spring框架下使用c3p0的数据库需要加入c3p0-0.9.1.2.jar(现在最新的)这个支持包.这里以数据同步项目为例: ...

  3. android-studio设置代理

    /home/{user}/.gradle/gradle.properties org.gradle.jvmargs=-Xmx1536m -DsocksProxyHost=127.0.0.1 -Dsoc ...

  4. Python自动化之select、greenlet和gevent和事件驱动模型初探

    进程.线程和协程的区别 进程拥有自己独立的堆和栈,既不共享堆,亦不共享栈,进程由操作系统调度. 线程拥有自己独立的栈和共享的堆,共享堆,不共享栈,线程亦由操作系统调度(标准线程是的). 协程和线程一样 ...

  5. Chord算法

    转自:http://blog.csdn.net/wangxiaoqin00007/article/details/7374833 虽然网上搜索CHord,一搜一大堆,但大多讲得不太清楚明白.今天发现一 ...

  6. Oracle 自定义函数Function

    示例代码: CREATE OR REPLACE  FUNCTION "MY_DATABASE"."F_GET_USER_COUNT_BY_DEPART" ( D ...

  7. Java面试题-线程安全

    1. 什么叫线程安全?servlet是线程安全吗?       答:如果你的代码所在的进程中有多个线程在同时运行,而这些线程可能会同时运行这段代码.如果每次运行结果和单线程运行的结果是一样的,而且其他 ...

  8. 《Linear Algebra and Its Applications》-chaper3-行列式-克拉默法则

    计算线性方程组唯一解的克拉默法则:

  9. Php Laravel框架 多表关系处理 之 Eloquent一对多关系处理

    Php Laravel框架 多表关系处理 之 Eloquent一对多关系处理 本博文主要介绍 Laravel 框架中 Eloquent  对一对多关系的处理以及在 Laravel Administra ...

  10. 关于sizeof的笔试面试题具体解释

    原创Blog,转载请注明处处 http://blog.csdn.net/hello_hwc 注意:sizeof是编译期计算出结果的,这一点对后面的理解非常重要 一.关于结构体 先看下代码 #inclu ...