Problem B. Geometry Problem
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88926#problem/B

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

题意

给你两个线段,让你构造一个圆,与每个线段都只相交一次

题解

首先如何判断这个线段和圆相交了一次:一个端点在圆内,一个在圆外

然后我们枚举四个点的中点,半径就取中点到端点的最小值,然后再随便加上一个0.005就好了

就AC了……

加0.05会WA8

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** struct node
{
double x,y;
};
node kiss1[];
node kiss2[];
double dis(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int check1(double r,double x,double y)
{
int flag=;
int flag1=;
node ttt;
ttt.x=x,ttt.y=y;
for(int i=;i<;i++)
{
if(dis(ttt,kiss1[i])<r)
flag++;
if(dis(ttt,kiss2[i])<r)
flag1++;
}
if(flag==&&flag1==)
return ;
return ;
}
int check(double x,double y)
{
double ans=inf;
node a;
a.x=x,a.y=y;
for(int i=;i<;i++)
{
ans = min(ans,dis(a,kiss1[i]));
ans = min(ans,dis(a,kiss2[i]));
}
ans+=0.005;
if(check1(ans,x,y))
{
printf("%.10f %.10f %.10f\n",x,y,ans);
return ;
}
return ;
}
int main()
{
srand((unsigned)time(NULL));
freopen("geometry.in","r",stdin);
freopen("geometry.out","w",stdout);
while()
{
for(int i=;i<;i++)
cin>>kiss1[i].x>>kiss1[i].y;
for(int i=;i<;i++)
cin>>kiss2[i].x>>kiss2[i].y;
if(kiss1[].x==&&kiss1[].y==&&kiss2[].x==&&kiss2[].y==&&kiss1[].x==&&kiss1[].y==&&kiss2[].x==&&kiss2[].y==)
break;
node a,b;
double ans=inf;
int flag = ;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
a = kiss1[i],b = kiss2[j];
double ansx=(a.x+b.x)/2.0;
double ansy=(a.y+b.y)/2.0;
if(check(ansx,ansy)==)
{
flag = ;
break;
}
}
if(!flag)
break;
}
if(!flag)
continue;
}
}

Codeforces Gym 100338B Geometry Problem 计算几何的更多相关文章

  1. Codeforces Gym 100338B Spam Filter 字符串哈希+贝叶斯公式

    原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...

  2. Hdu-6242 2017CCPC-哈尔滨站 M.Geometry Problem 计算几何 随机

    题面 题意:给你n个点,让你找到一个圆,输出圆心,和半径,使得有超过一半的点刚好在圆上.n<=1e5,题目保证了有解 题解:刚开始看着很不可做的样子,但是多想想,三点确定一个圆,三点啊! 现在有 ...

  3. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化 排列组合

    E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike ...

  4. 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 ...

  5. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】

    任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...

  6. 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 ...

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

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

  8. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化+逆元

    E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes input ...

  9. HDU1086 You can Solve a Geometry Problem too(计算几何)

    You can Solve a Geometry Problem too                                         Time Limit: 2000/1000 M ...

随机推荐

  1. Oracle日常维护脚本

    1.正常停库流程     ps -ef|grep LOCAL=NO|cut -c 9-15|xargs kill -9      shutdown immediate; 2.备份数据库     bac ...

  2. Oracle 课程五之优化器和执行计划

    课程目标 完成本课程的学习后,您应该能够: •优化器的作用 •优化器的类型 •优化器的优化步骤 •扫描的基本类型 •表连接的执行计划 •其他运算方式的执行计划 •如何看执行计划顺序 •如何获取执行计划 ...

  3. linux中waitpid及wait的用法

    wait(等待子进程中断或结束) 表头文件      #include<sys/types.h>      #include<sys/wait.h> 定义函数 pid_t wa ...

  4. 15、自定义Content Provider

     自定义Content Provider的步骤    1. 编写一个类,该类必须继承自ContentProvider类. 实现ContentProvider类中所有的抽象方法. 定义Content ...

  5. 11、WebView 使用总结

    <WebView android:id="@+id/webview" android:background="@color/white" android: ...

  6. android 布局居中

    android:layout_alignParentLeft="true" 位于父容器左上角 android:layout_alignParentBottom, android:l ...

  7. SPOJ DISUBSTR Distinct Substrings 后缀数组

    题意:统计母串中包含多少不同的子串 然后这是09年论文<后缀数组——处理字符串的有力工具>中有介绍 公式如下: 原理就是加上新的,减去重的,这题是因为打多校才补的,只能说我是个垃圾 #in ...

  8. HDU 5749 Colmerauer 单调队列+暴力贡献

    BestCoder Round #84   1003 分析:(先奉上zimpha巨官方题解) 感悟:看到题解单调队列,秒懂如何处理每个点的范围,但是题解的一句算贡献让我纠结半天 已知一个点的up,do ...

  9. DOS功能的调用

    DOS功能的调用:主要包含三方面的子程序:设备驱动(基本I/O),文件管理和其他(包括内存管理,自取时间,自取终端向量,总之程序等)随着DOS版本的升级,这种DOS功能调用的子程序数量也在不断的增加, ...

  10. 为cocos2d-x项目增加Lua支持

    开始为游戏增加Lua脚本支持,今天主要配置了一下开发环境:cocos2d-x 2.2.1,xcode5. 1. 创建cocos2d-x-lua项目 类似于创建C++项目,用以下命令即可: python ...