freckles
- 题目描述:
-
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.
- 输入:
-
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.
- 输出:
-
Your program prints a single real
number to two decimal places: the minimum total length of ink lines that
can connect all the freckles.
- 样例输入:
-
3
1.0 1.0
2.0 2.0
2.0 4.0
- 样例输出:
-
3.41
这道题就是输入n,和n个坐标
然后输出将所有点连起来的最短路径
还是最小生成树
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int path[]; struct edge{
int a,b;
double cost;
bool operator <(const edge &A) const{
return cost<A.cost;
}
}edge[]; int findroot(int a){
int temp=a;
while (path[a] != -){
a=path[a];
}
int temp2; while (path[temp]!= -){
temp2=path[temp];
path[temp]=a;
temp=temp2;
}
return a;
} int main (){
int n;
double point[][];
while (cin>>n){
int size=;
for (int i=;i<=n;i++){
cin>>point[i][]>>point[i][];
for (int j=;j<i;j++){
edge[size].a=i;
edge[size].b=j;
edge[size].cost=sqrt(pow(point[i][]-point[j][],2.0)+pow(point[i][]-point[j][],2.0));
size++;
}
} int nn=n*(n-)/;
for (int i=;i<=n;i++){
path[i]=-;
}
double ans=; sort(edge+,edge++nn);
int a,b;
for (int i=;i<=nn;i++){
a=edge[i].a;
b=edge[i].b;
a=findroot(a);
b=findroot(b);
if (a!=b){
path[a]=b;
ans += edge[i].cost;
}
} printf("%.2lf\n",ans);//输出精确到两位小数
}
return ; }
//图论的edge什么的下标都是从1开始的,而不是0比较方便
学会了输出两位小数怎么做
freckles的更多相关文章
- 10034 - Freckles 克鲁斯克尔最小生成树!~
/* 10034 - Freckles 克鲁斯克尔最小生成树!- */ #include<iostream> #include<cstdio> #include<cmat ...
- poj 2560 Freckles
题目连接 http://poj.org/problem?id=2560 Freckles Description In an episode of the Dick Van Dyke show, li ...
- 题目1144:Freckles(最小生成树进阶)
题目链接:http://ac.jobdu.com/problem.php?pid=1144 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- 九度OJ 1144:Freckles(斑点) (最小生成树)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1538 解决:760 题目描述: In an episode of the Dick Van Dyke show, little Richi ...
- POJ2560 Freckles
Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Description In an epis ...
- 【九度OJ】题目1144:Freckles 解题报告
[九度OJ]题目1144:Freckles 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1144 题目描述: In an ...
- UVA 10034 Freckles 最小生成树
虽然是道普通的最小生成树题目,可还是中间出了不少问题,暴露的一个问题是不够细心,不够熟练.所以这篇博客就当记录一下bug吧. 代码一:kruskal #include<stdio.h> # ...
- uva 10034 Problem A: Freckles
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- POJ 2560 Freckles Prime问题解决算法
这个问题正在寻求最小生成树. 给定节点的坐标,那么我们需要根据各个点之间的这些坐标来计算距离. 除了这是标准的Prime算法的,能源利用Prime基本上,你可以使用Kruskal. 经典的算法必须填写 ...
随机推荐
- container(容器),injection(注入)
1.container为什么会出现? 在书写程序的时候,我们常常需要对大量的对象引用进行管理.为了实现有效的归类管理,我们常常将同类的引用放置在同一数据容器中.由于数据容器中存放了我们随时可能需要使用 ...
- vue 文件目录结构详解
vue 文件目录结构详解 本篇文章主要介绍了vue 文件目录结构详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧 项目简介 基于 vue.js 的前端开发环境,用于前后 ...
- bash的基础特性
命令历史:history 环境变量: HISTSIZE: 命令历史的条数 HISTFILE:~/.bash_history HISTFILESIZE: 命令历史文件记录历史的条数 history -d ...
- POJ 2774 Long Long Message (二分 + Hash 求最长公共子串)题解
题意:求最长公共子串 思路:把两个串Hash,然后我们把短的作为LCS的最大可能值,然后二分长度,每次判断这样二分可不可以.判断时,先拿出第一个母串所有len长的子串,排序,然后枚举第二个母串len长 ...
- 【科普】GSM伪基站 劫持 诈骗?用4G网就安全?想强制用4G?最详细的科普教程在此!
最近在一些主流论坛(豆瓣.贴吧.虎扑.天涯)都出现了讨论GSM诈骗的新闻,很多受害者受骗. 1.什么是GSM劫持? 平时你的手机是连接到了运营商的基站,才能收到电话短信.伪基站就是有人也买了运营商的基 ...
- [原]编译flightGear
参考:flightgear编译博客201705 flightGear是三维飞行仿真软件,这个款软件是开源的,我们尝试用其源码完整编译一遍这个工程,并使用它. 它用到里以下扩展库: 空气动力学库:JSB ...
- 力扣(LeetCode)463. 岛屿的周长
给定一个包含 0 和 1 的二维网格地图,其中 1 表示陆地 0 表示水域. 网格中的格子水平和垂直方向相连(对角线方向不相连).整个网格被水完全包围,但其中恰好有一个岛屿(或者说,一个或多个表示陆地 ...
- css js 兼容问题
js 兼容问题 1. document.form.item 问题问题:代码中存在 document.formName.item("itemName") 这样的语句,不能在FF下运 ...
- gulp点滴
var gulp = require('gulp'), connect = require('gulp-connect'), browserify = require('gulp-browserify ...
- windows下如何批量修改文件名
windows下如何批量修改文件名 一.总结 一句话总结:就是用excel生成了多条修改文件名的dos命令然后执行,比较核心的就是把图片名称导入excel 将图片名称导入excel---编写如下DOS ...