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 ...
随机推荐
- CUDA编程-(2)其实写个矩阵相乘并不是那么难
程序代码及图解析: #include <iostream> #include "book.h" __global__ void add( int a, int b, i ...
- Test2014-3-1 魅力值比较
魅力值比较 [问题描述] 大学生恋爱的问题造成了数量众多的异地恋,有许多J大的女生早早被Q大男生追走,这导致了J大男生的强烈不满.就在吐血高调地向一位J大美女展开攻势的之后,J大男生终于爆发了. 为了 ...
- 【LeetCode】Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- MVC母版面,子页的脚本生成在最后
- 第一次尝试使用JAVA编写的ATM机程序
package study; import java.util.Scanner; public class ATM { private static int[] users = { 111111, 2 ...
- ASP.NET MVC- MvcPager
本文目标 一.能够使用MvcPager进行分页 本文目录 一.MvcPager控件的简单使用 二.C#扩展方法 一.MvcPager控件的简单使用 1.添加MvcPager.dll的引用[下载] 2. ...
- ASP.NET MVC提交到服务器的几种方法
多年不搞WEB开发了,最近有个小活干干,记录一下学习的心得. 以下为几种脚本向服务器提交的方法: 1. $.ajax({ type: "GET", url: "/Test ...
- Jsp的内置标签和jstl标签
1.内置标签(动作标签) 内置标签不需要再jsp页面导入标签 1).forward:请求的转发,格式如下 <%-- 作用与这个相同 <%request.getRequestDispatch ...
- android_handler(三)
这篇记录 android 消息机制中,MainThread 向 WorkThread 发送消息.( MainThread → WorkThread ) 步骤: 1.准备looper对象 2.在子线程中 ...
- FolderBrowserDialog
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog(); folderBrowserDial ...