n个点 最短路径
来源:互联网 发布:一个程序员的奋斗史txt 编辑:程序博客网 时间:2024/05/20 12:48
Problem B
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 2 Accepted Submission(s) : 1
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.<br>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?<br>
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. <br><br>Input contains multiple test cases. Process to the end of file.<br>
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. <br>
Sample Input
31.0 1.02.0 2.02.0 4.0
Sample Output
3.41
k 算法
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <cmath>#include <iomanip>using namespace std;struct point{ double x; double y;};double juli(double x, double y,double x1,double y1){ return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));}int main(){ int t; double x; double y; double a[105][105]; point b[106]; int i,j; int pao[1000]; while(cin>>t) { memset(pao,0,sizeof(pao)); for (i=1;i<=t;i++) { cin>>b[i].x; cin>>b[i].y; } for(i=1;i<=t;i++) for(j=i;j<=t;j++) { a[i][j]=juli(b[i].x,b[i].y,b[j].x,b[j].y); a[j][i]=a[i][j]; } double max; int k; double sum=0; for(i=2;i<=t;i++) { max=999999; for(j=2;j<=t;j++) { if(pao[j]==0&&max-a[1][j]>1e-8) { k=j; max=a[1][j]; } } pao[k]=1; sum+=max; for(j=2;j<=t;j++) { if(pao[j]==0&&a[k][j]-a[1][j]<1e-8) a[1][j]=a[k][j]; } } cout<<fixed<<setprecision(2)<<sum<<endl; } return 0; }
0 0
- n个点 最短路径
- dijkstra(n^2)求某个点到所有点的最短路径
- N-最短路径分词算法
- N-最短路径分词算法
- NLPIR分词之N-最短路径
- 点对的最短路径问题
- 全点对最短路径
- 单源最短路径和全点对最短路径算法
- 【BZOJ4016】最短路径树问题,最短路+点分治
- 中文分词之最短路径法和N最短路径
- 最短路径问题平面上有n个点(n<=100),每个点的坐标均在-10000~10000之间。其中的一些点之间有连线。若有连线,则表示可从一个点到达另一个点,即两点间有通路,通路的距离为两点间的直线距离。
- ICTCLAS分词系统研究(五)--N最短路径
- ICTCLAS分词系统研究(五)--N最短路径
- 中文分词预处理之N最短路径法小结
- 所有点对的最短路径-FloydWarshall算法
- 所有点对的最短路径-FloydWarshall算法
- 单发点无权最短路径C语言
- Floyd算法(所有点对最短路径)
- 动态规划学习
- 设计模式--适配器模式
- WebSQL
- leetcode-java-168. Excel Sheet Column Title
- 第十次盲打测试
- n个点 最短路径
- Java练习:OO.Objects_references
- 手机开发实战88——WAP介绍1
- Allowed memory size of 134217728 bytes exhausted
- Unity Shader简单Shader一
- 手机开发实战89——WAP介绍2
- linux下的sqlite入门
- 剑指Offer----面试题28:字符串的排列 & 去重
- JavaPoet源码初探