acdream 1414 Geometry Problem
Geometry Problem
Special Judge
Problem Description
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 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
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- CodeForces 689E Mike and Geometry Problem (离散化+组合数)
Mike and Geometry Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/I Description M ...
- Codeforces Gym 100338B Geometry Problem 计算几何
Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- you can Solve a Geometry Problem too(hdoj1086)
Problem Description Many geometry(几何)problems were designed in the ACM/ICPC. And now, I also prepare ...
- acdream 1222 Quantization Problem [dp]
称号:acdream 1222 Quantization Problem 题意:给出一个序列 a ,然后给出一个 n * m 的矩阵,让你从这个矩阵中选出一个序列k,使得sum(abs(ki - ai ...
- (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/ ...
- 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 ...
随机推荐
- iOS动画——DynamicAnimate
力学动画 以dynamicAnimate为首的力学动画是苹果在iOS7加入的API,里面包含了很多力学行为,这套API是基于Box2d实现的.其中包含了重力.碰撞.推.甩.和自定义行为. 涉及到的类如 ...
- session一致性架构设计实践.
一.缘起 什么是session? 服务器为每个用户创建一个会话,存储用户的相关信息,以便多次请求能够定位到同一个上下文. Web开发中,web-server可以自动为同一个浏览器的访问用户自动创建se ...
- 【深度学习笔记】(一)Mac下TensorFlow安装及环境搭建
本文由@ray 出品,转载请注明出处. 文章链接:http://www.cnblogs.com/wolfray/p/7828903.html 在学习了一段时间台大李宏毅关于deep learning ...
- mounted钩子问题
recommend.vue <script type="text/ecmascript-6"> import Slider from 'base/slider/slid ...
- docker安装后出现Cannot connect to the Docker daemon
启动docker service docker start docker安装后出现Cannot connect to the Docker daemon You need to add user in ...
- CSS 之自定义滚动条样式
::-webkit-scrollbar {/*滚动条整体样式*/ width: 5px; /*高宽分别对应横竖滚动条的尺寸*/ height: 1px; } ::-webkit-scrollbar-t ...
- %2d
%2d是C语言中printf函数的输出格式说明符. 具体解释如下: 使输出的int型的数值以2位的固定位宽输出.如果不足2位,则在前面补空格:如果超过2位,则按实际位数输出. 注:如果输出的数值不是i ...
- python 获取本机环境信息
一.函数 1.socket.gethostname():不带任何参数,返回一个字符串(主机名),通常不完整.比如csm.example.com 只会返回csm 2.socket.getfqdn():带 ...
- PHP 数据库连接 (Mysql Mysqli PDO)
1.PHP与Mysql扩展(本扩展自 PHP 5.5.0 起已废弃,并在将来会被移除),PHP原生的方式去连接数据库,是面向过程的 <?php $mysql_conf = array( 'hos ...
- bootstrap table 生成的表格里动态添加HTML元素按钮,JS中添加点击事件,点击没反应---解决办法
bootstraptable中onExpandRow属性---js 方法添加的 html代码,然后给这代码里面的 元素 添加 事件,却获取不该元素.(称之为未来元素),由于是未来的 所以现在没有这个 ...