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;
}

acdream 1414 Geometry Problem的更多相关文章

  1. HDU1086You can Solve a Geometry Problem too(判断线段相交)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  2. codeforces 361 E - Mike and Geometry Problem

    原题: Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him ...

  3. hdu 1086 You can Solve a Geometry Problem too

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  4. CodeForces 689E Mike and Geometry Problem (离散化+组合数)

    Mike and Geometry Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/I Description M ...

  5. Codeforces Gym 100338B Geometry Problem 计算几何

    Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

  6. you can Solve a Geometry Problem too(hdoj1086)

    Problem Description Many geometry(几何)problems were designed in the ACM/ICPC. And now, I also prepare ...

  7. acdream 1222 Quantization Problem [dp]

    称号:acdream 1222 Quantization Problem 题意:给出一个序列 a ,然后给出一个 n * m 的矩阵,让你从这个矩阵中选出一个序列k,使得sum(abs(ki - ai ...

  8. (hdu step 7.1.2)You can Solve a Geometry Problem too(乞讨n条线段,相交两者之间的段数)

    称号: You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...

  9. HDU 1086:You can Solve a Geometry Problem too

    pid=1086">You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Mem ...

随机推荐

  1. [ NOIP 2014 ] TG

    \(\\\) \(Day\ 1\) \(\\\) \(\#\ A\) \(Rps\) 定义五种方案的石头剪刀布游戏,两人共进行\(N\)局游戏,已知两人各自的循环节和具体方案,胜者得\(1\)分,败者 ...

  2. [转]STL之deque容器详解

    Deque 容器 deque容器是C++标准模版库(STL,Standard Template Library)中的部分内容.deque容器类与vector类似,支持随机访问和快速插入删除,它在容器中 ...

  3. [Android]异常9-自定义PopupWindow出现闪屏

    背景: 自定义PopupWindow使用时,Android4.0或者一些手机正常使用,Android6.0或者部分手机使用自定义PopupWindow触发事件时,出现闪屏 异常原因: 可能一>A ...

  4. T-SQL语句以及几个数据库引擎

    创建表 注意事项: A.自增长             B.数据库引擎, ISAM 是一个定义明确且历经时间考验的数据表格管理方法,它在设计之时就考虑到数据库被查询的次数要远大于更新的次数.因此,IS ...

  5. 移动web——媒体查询

    基本概念 响应式开发在没有媒体查询前,也可以通过js来实现,但是人们基本不会考虑,特别繁琐.在出现了媒体查询,才开始逐渐推广响应式.实际开发中,在时间与金钱充足的情况下还是别做响应式,影响性能,维护麻 ...

  6. (转)Struts2的标签库

    http://blog.csdn.net/yerenyuan_pku/article/details/68638679 Struts2的标签库 对于一个MVC框架而言,重点是实现两部分:业务逻辑控制器 ...

  7. Android Service初解

    Service是什么呢? 他同Activity相比,最大的不同就是他没有专门的Layout展示界面,他默默的工作在App的后台. 虽然除了少数几种情况,我们不需要使用Service,但我们也有必要了解 ...

  8. IDEA 创建一个普通的java项目

    IntelliJ IDEA 如何创建一个普通的java项目,及创建java文件并运行 首先,确保idea软件正确安装完成,java开发工具包jdk安装完成. IntelliJ IDEA下载地址:htt ...

  9. for循环提高内存访问效率的做法

    今天写程序的时候突然想到一点,记录一下: 计算机内存地址是线性排列组织的,而利用for循环对高维数组结构进行遍历处理的时候,要保证最内层for循环遍历的是高维数组的最低维度,这样可以最大化利用CPU的 ...

  10. Chat Group gym101775A(逆元,组合数)

    传送门:Chat Group(gym101775A) 题意:一个宿舍中又n个人,最少k(k >= 3)个人就可以建一个讨论组,问最多可以建多少个不同的讨论组. 思路:求组合数的和,因为涉及除法取 ...