Geometry Problem

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)    
Special Judge

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

题解及代码:

这道题目的做法 应该挺多的吧。我的解法不知道是不是对的,可是能AC(个人觉得是对的)。

首先我们从两条直线各取一个点。要求:两点的距离最短。之后我们把这两个点的中点作为圆的圆心,把圆心到两点的距离求出来记为r,然后求出圆心到另外两直线端点的距离r1,r2,半径R=(r+min(r1,r2))/2.0。即可了。

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; struct Point
{
double x,y;
Point(){}
Point(double X,double Y):x(X),y(Y) {}
}t; struct Line
{
Point l,r;
}a,b; double dis(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} void init()
{
double Dis[5]; Dis[1]=dis(a.l,b.l);
Dis[2]=dis(a.l,b.r);
Dis[3]=dis(a.r,b.l);
Dis[4]=dis(a.r,b.r); int p=1;
for(int i=2;i<=4;i++)
{
if(Dis[i]<Dis[p]) p=i;
} if(p==2)
{
t=b.r;b.r=b.l;b.l=t;
}
if(p==3)
{
t=a.l;a.l=a.r;a.r=t;
}
if(p==4)
{
t=a.l;a.l=a.r;a.r=t;
t=b.r;b.r=b.l;b.l=t;
}
} int main()
{
while(scanf("%lf%lf%lf%lf",&a.l.x,&a.l.y,&a.r.x,&a.r.y))
{
scanf("%lf%lf%lf%lf",&b.l.x,&b.l.y,&b.r.x,&b.r.y); if(!a.l.x&&!a.l.y&&!a.r.x&&!a.r.y&&!b.l.x&&!b.l.y&&!b.r.x&&!b.r.y)
break; init(); double x,y,r;
x=(a.l.x+b.l.x)/2.0;
y=(a.l.y+b.l.y)/2.0;
r=dis(Point(x,y),a.l); double r1,r2;
r1=dis(Point(x,y),a.r);
r2=dis(Point(x,y),b.r); r=r+min(r1,r2);
r/=2.0;
printf("%.5lf %.5lf %.5lf\n",x,y,r);
}
return 0;
}

最新文章

  1. Linux文件的建立、复制、删除和移动命令
  2. hdu1753java(大数相加)---BigDecimal类
  3. mini2440移植uboot-2008.10 (二) DM9000网卡驱动移植
  4. php 格式
  5. [读书笔记]设计原本[The Design of Design]
  6. Ajax跨域原理及JQuery中的实现
  7. malloc(0)
  8. 你真的了解word-wrap和word-break的区别吗? (转载)
  9. WEB框架Django之中间件/缓存/CBV/信号
  10. UVa 210 Concurrency Simulator (双端队列+模拟)
  11. Paxos与zookeeper
  12. 通过复制(拷贝)新建javaweb项目报错无法访问
  13. mssqlserver SQL注释快捷键
  14. React-Native基础_2.样式Style
  15. C++之shared_ptr总结
  16. spring 项目tomcat 8.0.2 发布报错:Could not initialize class org.hibernate.validator.engine.ConfigurationImpl
  17. Python的工具包[2] -&gt; matplotlib图像绘制 -&gt; matplotlib 库及使用总结
  18. Netflix Ribbon源码设计错误的证据(附正确示例)
  19. HTTP协议探索之Cache-Control
  20. JS[获取两个日期中所有的月份]

热门文章

  1. hibernate 级联删除报更新失败的问题(org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update)
  2. JS高级——缓存原理
  3. python中struct.pack()函数和struct.unpack()函数
  4. svg文件使用highmap显示
  5. 认识 java JVM虚拟机选项 Xms Xmx PermSize MaxPermSize 区别
  6. CAD动态绘制多段线(com接口)
  7. 简述prototype, _proto_, constructor三者的关系
  8. iPhone设备当前IP和SSID的获取
  9. forcedirectories和CreateDirectory
  10. PAT 1034. Head of a Gang