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

  1. 0 0 0 4
  2. 1 0 1 4
  3. 0 0 0 0
  4. 0 0 0 0

Sample Output

  1. 0.5 0 2

Hint

题解及代码:

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

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

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. struct Point
  7. {
  8. double x,y;
  9. Point(){}
  10. Point(double X,double Y):x(X),y(Y) {}
  11. }t;
  12.  
  13. struct Line
  14. {
  15. Point l,r;
  16. }a,b;
  17.  
  18. double dis(Point a,Point b)
  19. {
  20. return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  21. }
  22.  
  23. void init()
  24. {
  25. double Dis[5];
  26.  
  27. Dis[1]=dis(a.l,b.l);
  28. Dis[2]=dis(a.l,b.r);
  29. Dis[3]=dis(a.r,b.l);
  30. Dis[4]=dis(a.r,b.r);
  31.  
  32. int p=1;
  33. for(int i=2;i<=4;i++)
  34. {
  35. if(Dis[i]<Dis[p]) p=i;
  36. }
  37.  
  38. if(p==2)
  39. {
  40. t=b.r;b.r=b.l;b.l=t;
  41. }
  42. if(p==3)
  43. {
  44. t=a.l;a.l=a.r;a.r=t;
  45. }
  46. if(p==4)
  47. {
  48. t=a.l;a.l=a.r;a.r=t;
  49. t=b.r;b.r=b.l;b.l=t;
  50. }
  51. }
  52.  
  53. int main()
  54. {
  55. while(scanf("%lf%lf%lf%lf",&a.l.x,&a.l.y,&a.r.x,&a.r.y))
  56. {
  57. scanf("%lf%lf%lf%lf",&b.l.x,&b.l.y,&b.r.x,&b.r.y);
  58.  
  59. 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)
  60. break;
  61.  
  62. init();
  63.  
  64. double x,y,r;
  65. x=(a.l.x+b.l.x)/2.0;
  66. y=(a.l.y+b.l.y)/2.0;
  67. r=dis(Point(x,y),a.l);
  68.  
  69. double r1,r2;
  70. r1=dis(Point(x,y),a.r);
  71. r2=dis(Point(x,y),b.r);
  72.  
  73. r=r+min(r1,r2);
  74. r/=2.0;
  75. printf("%.5lf %.5lf %.5lf\n",x,y,r);
  76. }
  77. return 0;
  78. }

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. Laravel5.1学习笔记20 EloquentORM 关系

    Eloquent: Relationships Introduction Defining Relationships One To One One To Many Many To Many Has ...

  2. PHP流程控制语句(if,foreach,break......)

    背景:PHP程序中,必不可少的要用到流程控制语句.这次对于流程控制语句进行一些总结. 条件控制语句和循环控制语句是两种基本的语法结构,它们都是用来控制程序执行流程.也是构成程序的主要语法基础. 一.程 ...

  3. android黑科技系列——获取加固后应用App的所有方法信息

    一.前言 在逆向应用的时候,我们有时候希望能够快速定位到应用的关键方法,在之前我已经详细介绍了一个自己研发的代码动态注入工具icodetools,来进行动态注入日志信息到应用中,不了解的同学可以查看这 ...

  4. 转:java中static、final、static final的区别

    http://blog.csdn.net/qq1623267754/article/details/36190715 final可以修饰:属性,方法,类,局部变量(方法中的变量) final修饰的属性 ...

  5. CloseableHttpClient 在使用过程中遇到的问题

    代码是前辈写的,在对代码进行压测的时候遇到了个问题,最大线程是 不能超过setDefaultMaxPerRoute设置的数字,一点超过 就会死掉.这里会报错 connection pool shut ...

  6. 控制台——EventLog实现事件日志操作

    我们应该如何通过写代码的方式向其中添加“日志”呢? 在操作之前,先明确几个概念: 1:事件日志名(logName):“事件查看器”中的每一项,如“应用程序”.“Internet Explorer”.“ ...

  7. CNN结构:HSV中的饱和度解析

    参考:颜色的前世今生-饱和度 详解,划重点- 关键这个"纯"是指什么? 是指颜色明亮么?明度高的颜色看起来也明亮啊,不一定纯度高啊- 是说颜色鲜艳么?颜色 "不鲜艳&qu ...

  8. ProE复杂曲线方程:Python Matplotlib 版本代码(L系统,吸引子和分形)

    对生长自动机的研究由来已久,并在计算机科学等众多学科中,使用元胞自动机的概念,用于生长模拟.而复杂花纹的生成,则可以通过重写一定的生长规则,使用生成式来模拟自然纹理.当然,很多纹理是由人本身设计的,其 ...

  9. css nth-child 的应用

    最近改视频监控页面,由于窗口比较多,以前是通过计算窗口大小位置来处理页面布局的,其实还是比较麻烦,而且偶尔会有页面位置错乱的现象,虽然只是及其偶尔的现象,但总归是不好. 计算窗口位置的代码: /*监控 ...

  10. * 获取页面参数 * @return 参数打印

    /** * 获取页面参数 * @return 参数打印 */ GetUrlParam: function(paraName) { var url = document.location.toStrin ...