hdoj (1162) 最小生成树
Problem B
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 10 Accepted Submission(s) : 7
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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
Input contains multiple test cases. Process to the end of file.
Output
Sample Input
3 1.0 1.0 2.0 2.0 2.0 4.0
Sample Output
3.41
#include <stdio.h>
#include <math.h>
#include <string.h>
const int maxnum = 105;
const int maxint = 999999;
double dist[maxnum];
double prev[maxnum];
double c[maxnum][maxnum];
double ju(double x1,double x2,double y1,double y2)
{
return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
void dijkstra(int n,int v)
{
bool s[maxnum];
for(int i=1;i<=n;i++)
{
s[i] = 0;
dist[i] = c[v][i];
}
s[v] = 1;
for(int i = 2; i<=n; i++)
{
int u=v;
double temp = maxint;
for(int j = 1; j<=n; j++)
{
if(!s[j]&&dist[j]<temp)
{
temp = dist[j];
u = j;
}
}
s[u] = 1;
for(int j = 1; j<=n; j++)
{
if(!s[j])
{
double newdist = dist[j] + c[u][j];
if(newdist<c[u][j])
{
dist[j] = newdist;
}
}
}
}
}
int main()
{
int n;
double x[105],y[105];
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&x[i],&y[i]);
}
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
c[i][j] = ju(x[i],x[j],y[i],y[j]);
c[j][i] = c[i][j];
}
c[i][i] = 0;
}
dijkstra(n,1);
printf("%.2lf\n",dist[n]);
}
}
为什么结果不正确?
hdoj (1162) 最小生成树的更多相关文章
- 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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDOJ 1162
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDOJ 1301最小生成树的Kruskal算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 将结点的字符信息处理成点信息即可,代码如下: #include<bits/stdc++.h ...
- hdu1162Eddy's picture
http://acm.hdu.edu.cn/showproblem.php?pid=1162 最小生成树 #include<iostream> #include<stdio.h> ...
- 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 (Kruskal算法,prim算法,最小生成树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 [题目大意] 给你n个点的坐标,让你找到联通n个点的一种方法.保证联通的线路最短,典型的最小生成 ...
- HDU 1162 Eddy's picture (最小生成树 prim)
题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...
- (最小生成树)Eddy's picture -- hdu -- 1162
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1162 Time Limit: 2000/1000 MS (Java/Others) Memory ...
随机推荐
- [comparator] 策略模式
我们知道策略模式,首先是各种策略可以替换,其实我们常见的Arrays.sort();中可以指定比较器,实现comparator接口的比较器,作为对象传入,这不就是策略模式吗,好理解吧
- Jquery扩展- 倒计时
Source Code (function($) { $.fn.countdown = function(options) { // default options var defaults = { ...
- node begining
node begining */--> pre { background-color: #2f4f4f;line-height: 1.6; FONT: 10.5pt Consola," ...
- poj 1274 The Perfect Stall【匈牙利算法模板题】
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20874 Accepted: 942 ...
- phpstudy配置虚拟主机
配置 phpstudy 虚拟主机 1在httpd.conf中 把#Include conf/extra/httpd-vhosts.conf前面的#去掉 2在站点域名管理 添加 要配置的 虚拟主机 添 ...
- ASP.NET MVC- MvcPager
本文目标 一.能够使用MvcPager进行分页 本文目录 一.MvcPager控件的简单使用 二.C#扩展方法 一.MvcPager控件的简单使用 1.添加MvcPager.dll的引用[下载] 2. ...
- 【OpenCV】基于kmeans的细胞检测方法
问题是这样的,有一幅经过二值化处理之后的图像,我们希望统计其中细胞的个数,和不同粘连情况的细胞个数,比如,下图中有1个细胞组成连通区域的,也有2个细胞组成连通区域的,也有更多个细胞组成连通区域的,我们 ...
- 在code.org上自己写一个flappy bird游戏
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:在code.org上自己写一个flappy bird游戏.
- rails + mongoid 使用
1. 测试环境 2. 创建工程 rails new mongoid_app --skip-active-record --skip-test-unit --skip-bundle 3. 修改gemfi ...
- docker rancher 负载均衡做路由跳转
介绍 我们要实现的目的是 根据负载均衡 跳转到指定的应用容器中 负载均衡中配置好 跳转的地址 当执行URL 请求的时候会自动跳转 测试方法 curl -v --header 'Host:mu.03in ...