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
![](http://acdream.info/img/prob/1414/1.jpg)
题解及代码:
这道题目的做法 应该挺多的吧。我的解法不知道是不是对的,可是能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 ...
随机推荐
- C#入门经典 Chapter1&2
Chapter1 1.1 .Net Framework的内容 主要包含一个庞大的代码库,可以在客户端通过OOP来使用这些代码(OOP:Object Oriented Programming面对对象程序 ...
- Android基础TOP2:单机按钮改变字体颜色
---恢复内容开始--- Activity: <TextView android:id="@+id/t1" android:textSize="30dp" ...
- IE9的F12工具,"网络"页签,点击"开始捕获"之后,请求显示的状态是"挂起"的分析和解决
最近一个项目,客户端使用用jQuery编写ajax请求,服务端采用struts2框架.js发送请求和action处理请求过程中,遇到一个问题.刚开始觉得问题很诡异,仔细定位很久之后才发现问题,虽然问题 ...
- css特殊效果
border-radius实现特殊形状 .box{ width: 100px; height: 100px; background: orange; border: 1px solid #000; b ...
- Lazarus 1.6 增加了新的窗体编辑器——Sparta_DockedFormEditor.ipk
一下是该控件官网的介绍 "Hello A package for a docked form editor can be found in : components/sparta/docke ...
- 【sqli-labs】 less56 GET -Challenge -Union -14 queries allowed -Variation3 (GET型 挑战 联合查询 只允许14次查询 变化3)
单引号括号闭合 http://192.168.136.128/sqli-labs-master/Less-56/?id=1')%23 http://192.168.136.128/sqli-labs- ...
- rrdtool 实践
rrdtool 实践 rrdtool 参数比较多,如果直接看文档,不知从何入手,直接从例子入手这样容易理解,模拟网卡流量 1. 创建数据库 rrdtool create Flow.rrd --star ...
- LeetCode--不同路径
一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” ).机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为“Finish”).现在考虑网格中 ...
- Ansible 利用playbook批量部署mariadb
环境说一下 192.168.30.21 ansible 192.168.30.25 client1 192.168.30.26 client2 这里我的ansible环境已经部 ...
- awk 新手入门笔记
转自:http://www.habadog.com/2011/05/22/awk-freshman-handbook/ awk新手入门笔记 @作者 : habadog@邮箱 : habadog1203 ...