Problem Description

      Peter is studying in the third grade of elementary school. His teacher of geometry often gives him difficult home tasks.

      At the last lesson the students were studying circles. They learned how to draw circles with compasses. Peter has completed most of his homework and now he needs to solve the following problem. He is given two segments. He needs to draw a circle which
intersects interior of each segment exactly once.

      The circle must intersect the interior of each segment, just touching or passing through the end of the segment is not satisfactory.

      Help Peter to complete his homework.

 

Input

      The input file contains several test cases. Each test case consists of two lines.

      The first line of the test case contains four integer numbers x11, y11,
x12, y12— the coordinates of the ends
of the first segment. The second line contains x21. y21,
x22, y22 and describes the second
segment in the same way.

      Input is followed by two lines each of which contains four zeroes these lines must not be processed.

      All coordinates do not exceed 102 by absolute value.

Output

      For each test case output three real numbers — the coordinates of the center and the radius of the circle. All numbers in the output file must not exceed 1010 by
their absolute values. The jury makes all comparisons of real numbers with the precision of 10-4.

Sample Input

0 0 0 4
1 0 1 4
0 0 0 0
0 0 0 0

Sample Output

0.5 0 2

Hint

Source

Andrew Stankevich Contest 22

这题是几何题,先把线段的端点都连起来,共4条线段,然后选择最短的那条线段,取这条线段的中点,中点即为圆心,半线段长为l1,算出这个点到另外两点连线的较小长度l2,然后圆的半径就是(l1+l2)/2;

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
#define inf 88888888
struct node{
double dis,x,y,xx,yy;
}a[10]; struct student{
double x,y;
}b[10]; double dist(double x,double y ,double xx,double yy){
return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));
} bool cmp(node a,node b){
double temp;
if(a.dis>b.dis){
temp=a.x;a.x=b.x;b.x=temp;
temp=a.xx;a.xx=b.xx;b.xx=temp;
temp=a.yy;a.yy=b.yy;b.yy=temp;
temp=a.y;a.y=b.y;b.y=temp;
return a.dis<b.dis;
}
return a.dis<b.dis;
} int main()
{
int n,m,i,j;
double x,y,dis1,dis2,x2,y2,x3,y3,x4,y4,x5,y5,disend,len;
while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x2,&y2,&x3,&y3,&x4,&y4,&x5,&y5)!=EOF)
{
if(x2==0 && y2==0 && x3==0 && y3==0 && x4==0 && y4==0 && x5==0 && y5==0)break;
a[1].dis=dist(x3,y3,x5,y5);a[1].x=x3;a[1].y=y3;a[1].xx=x5;a[1].yy=y5;
a[2].dis=dist(x2,y2,x4,y4);a[2].x=x2;a[2].y=y2;a[2].xx=x4;a[2].yy=y4;
a[3].dis=dist(x3,y3,x4,y4);a[3].x=x3;a[3].y=y3;a[3].xx=x4;a[3].yy=y4;
a[4].dis=dist(x2,y2,x5,y5);a[4].x=x2;a[4].y=y2;a[4].xx=x5;a[4].yy=y5;
sort(a+1,a+5,cmp);
x=(a[1].x+a[1].xx)/2;
y=(a[1].y+a[1].yy)/2;
b[2].x=x2;b[2].y=y2;
b[3].x=x3;b[3].y=y3;
b[4].x=x4;b[4].y=y4;
b[5].x=x5;b[5].y=y5; len=inf;
for(i=2;i<=5;i++){
if((b[i].x==a[1].x && b[i].y==a[1].y) || (b[i].x==a[1].xx && b[i].y==a[1].yy))continue;
if(dist(b[i].x,b[i].y,x,y)<len)
len=dist(b[i].x,b[i].y,x,y);
}
disend=(len+a[1].dis/2.0)/2;
printf("%.4f %.4f %.4f\n",x,y,disend);
}
return 0;
}

最新文章

  1. MyEclipse 2016正式版更新内容
  2. s5pv210编译qt
  3. Python强化训练笔记(四)——字典的排序
  4. DateTimePicker 控件的格式设置
  5. angularjs: ng-select和ng-options
  6. 实体框架 (EF) 入门 =&gt; 五、连接和模型
  7. solr教程,值得刚接触搜索开发人员一看
  8. ZOJ 2676 Network Wars ★(最小割算法介绍 && 01分数规划)
  9. Audit(查看审核/审计信息)
  10. QT中使用Glut库
  11. (C#)Windows Shell 编程系列4 - 上下文菜单(iContextMenu)(二)嵌入菜单和执行命令
  12. ASP.NET 依赖注入。
  13. TOGAF架构能力框架之架构能力建设和架构治理
  14. [日推荐] 『Streeter』极乐商店邀你一起来尬舞啊!-store.dreawer.com
  15. 邓_php面试【003】——完整版
  16. Spring boot读取application.properties中文乱码
  17. Pytorch 报错总结
  18. s5-11 距离矢量路由选择协议
  19. 【题解】 Luogu P1402 酒店之王 (二分图匹配)
  20. 转:Vue-cli proxyTable 解决开发环境的跨域问题

热门文章

  1. 了解一下ajax
  2. LeetCode1022. 从根到叶的二进制数之和
  3. LeetCode783. 二叉搜索树节点最小距离
  4. Zabbix监控虚拟机服务-告警与自动恢复
  5. USB过压保护芯片,高输入电压充电器(OVP)
  6. 前端知识(二)01-NPM包管理器-谷粒学院
  7. Django-html文件实例
  8. 关掉IE提示“当前安全设置会使计算机有风险”
  9. 让绝对定位的div居中
  10. 墓碑机制与 iOS 应用程序的生命周期