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. 经典的算法必须填写 ...
随机推荐
- win10忘记开机密码无法进入桌面
第一种: 电脑用微软账户登录,但密码始终不正确. 登陆这个网址 https://account.live.com/password/reset 按照提示的操作利用之前注册信息一步步重设密码 最后 ...
- 高度自适应不能触发transition的解决方法
1. 前言 在我们不能确定一个元素的高度的时候,要使用transition过渡,是不会触发的,比如一个p标签 内容行数不固定 我们可能就要初始 height: 0 ; 过渡到 height: au ...
- nginx 高并发优化参数
关于内核参数的优化: net.ipv4.tcp_max_tw_buckets = 6000timewait的数量,默认是180000.net.ipv4.ip_local_port_range = 10 ...
- Docker Compose 常用命令
Compose常用选项 # docker-compose主命令后面跟其他命令 docker-compose Usage: docker-compose [-f <arg>...] [opt ...
- Spring错误——Spring AOP——org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
背景:学习切面,测试前置通知功能,xml配置如下 <?xml version="1.0" encoding="UTF-8"?> <beans ...
- tomcat下面web应用发布路径配置 ( 即虚拟目录配置 )
https://blog.csdn.net/AnQ17/article/details/52122236
- Spring Boot Log4j2 日志学习
简介 Java 中比较常用的日志工具类,有: Log4j. SLF4j. Commons-logging(简称jcl). Logback. Log4j2(Log4j 升级版). Jdk Logging ...
- eclipse中如何在当前工程中查找一个字符串
ctrl + h 后弹出 tab选项,你选择 file search 然后在下面输入要查找的字符串workset 那里选择你要查找的项目默认是全部项目进行查找
- 【三】jquery之选择器
转自:https://www.cnblogs.com/youfeng365/p/5846650.html jquery参考手册:http://jquery.cuishifeng.cn/index.ht ...
- ABP权限认证
通过AOP+特性实现 ABP默认的权限验证过滤器 AbpAuthorizationFilter 可以通过继承AsyncAuthorizationFilter 自定义自己的权限过滤器 权限数据存放表 ...