题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3716

Ribbon Gymnastics


Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge


Robert is a gymnastics coach. Unfortunately, he got four gymnastics beginners to attend the coming competition. Since the competition has a nice award, Robert will make all his effort to win the competition.

One performance requires that each of the four player should take a ribbon and rotate herself, and assume the ribbons will then straighten out. Since Robert's four players are beginners, Robert cannot control the actual rotating speeds of four players during the competition. And when two ribbons touch, they may wind, which will cause players felling down. For safety, Robert should avoid this. Four distinct points will be given as xi yi before the competition begins. Players should stand at those points when rotating.

The longer the ribbons are, the more bonus Robert will gain. After knowing the four points Robert can choose ribbons and points for each player. The length of each ribbon should be positive. So help Robert to find the maximal total lengths of the four ribbons.

Input

There will be multiple test cases.Please process to the end of input.

Each test case contains four lines.

Each line contains two integers xi (-10^8≤xi≤10^8) and yi (-10^8≤yi≤10^8).

Output

Output the total maximal sum of the lengths of the four ribbons. Answer having an absolute or relative error less than 1e-6 will be accepted.

Sample Input

0 0
0 3
4 0
4 3

Sample Output

6.00000000

题意:给定4个点,以这4个点为圆心画圆,要求圆两两不能相交,求出满足条件的最大圆半径。

可以考虑贪心的想法,半径最大的情况一定是相切的情况,此时两圆的半径之和等于圆心距。但需要注意的是要保证圆不能相交,因此选择的半径要较小,否则会与其他圆相交。

(其实说到这里都只是一个理解的过程。贪心的证明都不是很简单,所以还是等着大神去搞吧。。)

四个点总共可以组成六条线段,从中选两个点组成线段,再选另外两个点组成线段,他们的距离之和最小的一种情况,就是半径之和最大的情况。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;struct point
{double x,y;point(){}point(double _x,double _y){x=_x;y=_y;}point operator - (const point &b) const{return point(x-b.x,y-b.y);}double len(){return sqrt(x*x+y*y);}
}p[5];double dis1,dis2,dis3;double dis(point a,point b)
{return (a-b).len();
}int main()
{while (scanf("%lf%lf",&p[1].x,&p[1].y)!=EOF){for (int i=2;i<=4;i++){scanf("%lf%lf",&p[i].x,&p[i].y);}dis1=dis(p[1],p[2])+dis(p[3],p[4]);//求出三对线段的距离之和dis2=dis(p[1],p[3])+dis(p[2],p[4]);dis3=dis(p[1],p[4])+dis(p[3],p[2]);double ans=min(dis1,min(dis2,dis3));//找出最小值printf("%.8lf\n",ans);}return 0;
}

ZOJ3716 Ribbon Gymnastics(贪心)相关推荐

  1. zoj 3716 Ribbon Gymnastics【神奇的计算几何】

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3716 来源:http://acm.hust.edu.cn/vjudg ...

  2. ZOJ:3716 Ribbon Gymnastics

    比赛的时候曾经一度想到了这种做法.直接用数学关系推导,但是当时觉得可能不对,所以干脆没有写... 没想到了... 转载一篇代码: #include<cstdio> #include< ...

  3. ZOJ 3716 - Ribbon Gymnastics

    题意:给出4个点坐标,以4个点为圆心画四个圆,四个圆不能相交,求最大半径和 一共4个点,最短的两条不共点的线段之和即为答案 #include <stdio.h> #include < ...

  4. ZOJ 3716 Ribbon Gymnastics 解题报告

    BUPT Summer training 1 题目 题意: 有四个点,在每个点画一个圆,互相不能重叠,求最大的半径和. 题解: 可知任意两条边的和有一个上限.必定至少有两条边的和等于上限,所以先枚举是 ...

  5. 【微服务架构】SpringCloud使用Ribbon实现负载均衡

    说在前面 软负载均衡的实现方式有两种,分别是服务端的负载均衡和客户端的负载均衡 服务端负载均衡:当浏览器向后台发出请求的时候,会首先向反向代理服务器发送请求,反向代理服务器会根据客户端部署的ip:po ...

  6. 算法设计与分析第3章 贪心算法

    第4章 贪心算法 贪心算法总是作出在当前看来最好的选择.也就是说贪心算法并不从整体最优考虑,它所作出的选择只是在某种意义上的局部最优选择. 贪心算法的基本要素 1.贪心选择性质 所谓贪心选择性质是指所 ...

  7. 贪心算法单源点最短路径例题c语言源代码,Dijkstra算法是解单源最短路径问题的一个贪心算法...

    问题描述 给定一个带权有向图 G=(V,E) ,其中每条边的权是一个非负实数. 另外,还给定 V 中的一个项点,称为源. 现在我们要计算从源到所有其他各项点的最短路径长度. 这里的长度是指路上各边权之 ...

  8. Too Many Segments CF595D 贪心乱搞

    传送门! 比赛的时候没有时间写了,看看了看大佬的代码,学习学习. 一开始实验室大佬说是用差分写的,但是看了代码发现打cf的人大家都是stl狂魔! 贪心思路:区间按照左端点排序,从1~2e5遍历每一个点 ...

  9. Roundgod and Milk Tea 贪心

    这个题好像可以用一种类似与置换的贪心方法来做~ sum记为剩余奶茶,一开始sum等于奶茶和 ans记录已经喝的奶茶数 不用排序,我们就从前往后直接处理,考虑的是每一个班最多可以喝多少杯奶茶 就是从剩余 ...

最新文章

  1. linux创建用户并授予sudo权限
  2. 简单的c语言课程设计管理类,C语言课程设计-学生成绩简单管理程序.doc
  3. zoj - 3502 Contest
  4. hdu1058(dp||优先队列)
  5. SCVMM 2012 R2运维管理十三之:将资源添加到VMM库
  6. cuda的global memory介绍
  7. linux brctl命令,Linux中brctl命令起什么作用呢?
  8. 9206晚自习点歌功能拆解 图片加载 控件显示与隐藏等等
  9. 千万条数据快速导入MySQL
  10. 让你“爱”上 GitHub,解决访问时图裂、加载慢的问题
  11. GoAhead WebServer 架构
  12. GID绘图和CDC类
  13. 【转】关于输出用%lf和%f的问题
  14. Atitit.词法分析的原理 理论
  15. Java后端开发实习记录
  16. 2021年中国研究生数学建模竞赛D题——抗乳腺癌候选药物的优化建模
  17. 网络安全实验室-脚本关1-15
  18. UI设计工作流程步骤详解,让你快速了解UI设计!
  19. windows10专业版镜像
  20. 爬取起点小说网免费小说

热门文章

  1. 读《终身成长》知 我命由我不由天 馁
  2. 短线选股操作常用技巧
  3. 『煮酒论史』 [近代风云]国军抗战的历史,十分震惊
  4. CSS绘制三角形原理及应用
  5. 废除闰秒真的有必要吗?不废除会有哪些影响?
  6. AngularJs 总结
  7. UI——day6.引导页的设计
  8. 人机工程学座椅设计_人机工程学椅子的尺寸和设计
  9. Pangu and Stones (hihocoder 1636)
  10. 为了搞明白统计套利,从两组序列之间的关系说起