博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU上一道最小生成树模板题的练习
阅读量:4299 次
发布时间:2019-05-27

本文共 2364 字,大约阅读时间需要 7 分钟。

Eddy's picture

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)

Total Submission(s) : 7   Accepted Submission(s) : 4

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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

31.0 1.02.0 2.02.0 4.0

Sample Output

3.41

Author

eddy

 

 

唔 这道题呢是一道很简单的最小生成树问题 大意就是给你n个点的坐标,让你使得这些点都能够连在一起而且路径最短,显然这道题可以用Prim算法的模板进行套用,但是唯一需要注意的一个地方就是,因为这道题给你的是n个点的坐标,而你需要将各个坐标一一转化为这n个点的边长再进行Prim算法的操作,所以在这之前还得再加上一个函数,专门用来计算两点间的距离,当然n个点坐标的存储用结构体会方便许多,那么这些前期工作做好了 再按照题意进行输入输出就可以了。。。当然今天交的时候不小心在初始化vis数组的时候写成了memset(vis,0,sizeof(0))然而样例只有一组所以不影响结果我也没有去管 看了样例过了就交了两次结果连着WA了,下次这种低级错误还是尽可能的避免才好= = 代码如下

#include
#include
#include
#include
#include
using namespace std;double d[10005];double map[10005][10005];int vis[10005];int n;const double MAX=1000000.0;struct Point { double x; double y; }point[10005];double dis(int i,int j){ return (double)sqrt((point[i].x-point[j].x)*(point[i].x-point[j].x)+(point[i].y-point[j].y)*(point[i].y-point[j].y));}double Prim(int n){ int i,j,id; double mins,ans=0; for(i=0;i
d[i]) { mins=d[i]; id=i; } } if(mins==MAX) return -1; vis[id]=1; ans+=mins; for(i=0;i
>point[i].x>>point[i].y; } for(i=0;i

 

转载地址:http://fupws.baihongyu.com/

你可能感兴趣的文章
python监控mysql连接数 批量杀进程 解决too many connections问题
查看>>
MySQL show processlist过滤
查看>>
mac os本地通过跳板机可视化连接服务器的mysql、mongodb、redis
查看>>
Python创建不可变的类实例
查看>>
Ajax发送、上传文件,Django后端接收、获取文件
查看>>
requests模块访问api接口小记,requests.request、requests.get和requests.post
查看>>
Python解决中文和空格对齐问题
查看>>
用Python的mutagen模块获取MP3音频文件的时长
查看>>
利用Python的pydub模块将二进制音频保存成普通的MP3、WAV文件
查看>>
解决安装oh-my-zsh后workon切换虚拟环境命令不起作用
查看>>
Python日志logging的levelname格式化参数1.1s小记
查看>>
pytest-cov插件计算单元测试代码覆盖率
查看>>
ubuntu虚拟机VMware桥接模式无法自动化获取IP的解决方法
查看>>
Python debug 报错:SystemError: unknown opcode
查看>>
Python将树结构转换成字典形式的多级菜单结构,写入json文件
查看>>
基于Python镜像制作讯飞语音实时识别docker镜像记录
查看>>
关闭linux防火墙让windows宿主机访问ubuntu虚拟机web服务以及docker
查看>>
pycharm 找不到同目录文件,但是终端中正常的小记
查看>>
安装了grpc但是无法导入:ImportError: No module named 'grpc'
查看>>
Python3调用腾讯实时语音识别示例
查看>>