UVa10034/POJ2560_Freckles(最小生成树)(小白书图论专题)
来源:互联网 发布:100寸投影幕 布 淘宝 编辑:程序博客网 时间:2024/06/06 07:35
解题报告
题意:
把所有点连起来,求使用的墨水最少。
思路:
裸最小生成树。
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#define inf 0x3f3f3f3fusing namespace std;struct N { double x,y;} node[110];int vis[110],n;double mmap[110][110],dis[110];double disc(N a,N b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}void prim() { int u; double minn,ans=0; for(int i=0; i<n; i++) { dis[i]=mmap[0][i]; vis[i]=0; } dis[0]=0; vis[0]=1; for(int i=0; i<n-1; i++) { minn=(double)inf; for(int j=0; j<n; j++) { if(!vis[j]&&dis[j]<minn) { minn=dis[j]; u=j; } } vis[u]=1; ans+=minn; for(int j=0; j<n; j++) { if(!vis[j]&&mmap[u][j]<dis[j]) { dis[j]=mmap[u][j]; } } } printf("%.2lf\n",ans);}int main() { int t,i,j;// scanf("%d",&t);// while(t--) { scanf("%d",&n); for(i=0; i<n; i++) { scanf("%lf%lf",&node[i].x,&node[i].y); } for(i=0; i<n; i++) { for(j=0; j<n; j++) { mmap[i][j]=mmap[j][i]=disc(node[i],node[j]); } } prim();// if(t)printf("\n");// } return 0;}
Freckles
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7004 Accepted: 3448
Description
In an episode of the Dick Van Dyke show, little Richie connects the freckles on his Dad's back to form a picture of the Liberty Bell. Alas, one of the freckles turns out to be a scar, so his Ripley's engagement falls through.
Consider Dick's back to be a plane with freckles at various (x,y) locations. Your job is to tell Richie how to connect the dots so as to minimize the amount of ink used. Richie connects the dots by drawing straight lines between pairs, possibly lifting the pen between lines. When Richie is done there must be a sequence of connected lines from any freckle to any other freckle.
Consider Dick's back to be a plane with freckles at various (x,y) locations. Your job is to tell Richie how to connect the dots so as to minimize the amount of ink used. Richie connects the dots by drawing straight lines between pairs, possibly lifting the pen between lines. When Richie is done there must be a sequence of connected lines from any freckle to any other freckle.
Input
The first line contains 0 < n <= 100, the number of freckles on Dick's back. For each freckle, a line follows; each following line contains two real numbers indicating the (x,y) coordinates of the freckle.
Output
Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the freckles.
Sample Input
31.0 1.02.0 2.02.0 4.0
Sample Output
3.41
Source
Waterloo local 2000.09.23
2 0
- UVa10034/POJ2560_Freckles(最小生成树)(小白书图论专题)
- 最小生成树-Uva10034
- uva10034 最小生成树
- UVA10034 - Freckles(最小生成树)
- 最小生成树专题
- 最小生成树专题
- 最小生成树专题
- 最小生成树专题
- (专题)最小生成树
- 专题六-最小生成树
- UVa10369/POJ2349_Arctic Network(最小生成树)(小白书图论专题)
- UVa10397_Connect the Campus(最小生成树)(小白书图论专题)
- Kuangbin Flying 6最小生成树专题
- 【各大OJ】最小生成树专题
- 【最小生成树入门专题1】G
- 【最小生成树入门专题1】A
- 【最小生成树入门专题1】C
- 【最小生成树入门专题1】H
- HTTP常见的错误
- Java遍历Set集合
- 吐哈录井信息平台入口流量参数不正确的解决办法
- python按value排序
- bitmap的处理,尽量避免OOM
- UVa10034/POJ2560_Freckles(最小生成树)(小白书图论专题)
- java获取当前时间 返回相应格式的时间
- UF超滤膜:分析超滤膜系统相关性能原理
- 搜索
- 7种形式的Android Dialog使用举例
- 三天打鱼两天晒网
- HttpUrlConnection模拟post表单进行文件上传
- Eclipse 集成
- Oracle CASE WHEN 用法介绍