【hdoj 1162】Eddy's picture
来源:互联网 发布:英语面试 知乎 编辑:程序博客网 时间:2024/05/12 17:13
Eddy's picture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8326 Accepted Submission(s): 4226
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8326 Accepted Submission(s): 4226
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
最小生成树prim算法
code:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <map>#include <set>#include <cmath>using namespace std;int v[105];double mp[105][105];struct point{ double x,y;}a[105];double dist(point a,point b){ double t; t = sqrt((a.x-b.x)*(a.x-b.x)*1.0+1.0*(a.y-b.y)*(a.y-b.y)); return t;}double prim(int n){ double sum = 0; v[0] = 1; int f; while(1) { int flag = 0; double mi = 100000000; for(int i = 0; i < n; i++){ if(!v[i]){ flag = 1; break; } } if(flag){ for(int i = 0; i < n; i++){ if(v[i]){ for(int j = 0; j < n; j++){ if(mp[i][j] < mi && i!=j && !v[j]){ mi = mp[i][j]; f = j; } } } } sum += mi; v[f] = 1; } else return sum; }}int main(){ int n; double x,y; while(scanf("%d",&n)!=EOF) { memset(v,0,sizeof(v)); for(int i = 0; i < n; i++){ scanf("%lf%lf",&x,&y); a[i].x = x; a[i].y = y; } for(int i = 0; i < n; i++){ for(int j = i+1; j < n; j++){ mp[i][j] = mp [j][i] = dist(a[i],a[j]); } } printf("%.2lf\n",prim(n)); } return 0;}
0 0
- HDOJ 1162 Eddy's picture
- HDOJ Eddy's picture 1162
- hdoj-1162-Eddy's picture
- hdoj 1162 Eddy's picture
- 【hdoj 1162】Eddy's picture
- HDOJ 1162 Eddy's picture
- HDOJ Eddy's picture
- ACM HDOJ 1162 (Eddy's picture)
- HDOJ--1162--Eddy's picture(包含题意)
- 1162 Eddy's picture
- Eddy's picture 1162
- HDOJ 1162:Eddy's picture 求解最小生成树
- HDOJ 1162 Eddy's picture(最小生成树 - kruskal)
- HDOJ 题目1162 Eddy's picture(最小生成树)
- hdoj 1162 Eddy's picture 【最小生成树】
- hdoj 1162 Eddy's picture(最小生成树)
- HDOJ 1162 Eddy's picture(最小生成树--kruskal)
- HDOJ 1162 Eddy's picture(最小生成树prim算法)
- 第三周项目1 顺序表的基本运算(2)
- sql server中的outer apply ,across apply 对应 oracle
- 什么是“大端”和“小端”及一段测试本机大端还是小端的代码
- Android——Canvas(画布)的使用
- JQuery中的$.when()对象
- 【hdoj 1162】Eddy's picture
- 【第3周 项目4 - 顺序表应用】
- 第3周项目3求集合并集
- 第3周项目4-顺序表应用问题(2)
- 数据库中间件Mycat诞生记1
- 屏幕旋转
- Eclipse背景颜色修改
- 数值拟合
- git学习