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. JOB的创建,定时,执行

    --建表 create table test_job(para_date date);  commit;  insert into test_job values(sysdate);  commit; ...

  2. 【原】cocos2d-x 2.0.4 不支持https协议 CURLE_UNSUPPORTED_PROTOCOL

    我们项目组用的cocos2d-x版本还比较老,各种好的功能不能用. 今天就让我遇到一个问题,使用CCHttpClient发送http请求的时候,https协议的不支持,返回失败信息如下 errorco ...

  3. js把div固定在页面的右下角

    在公司做材料系统中,需要做一个总是居于右下角的div,但是因为右边这部分本就是用iframe做的,所以是不好弄的. 一开始,以为用position:fixed,一句css就可以完成,结果在iframe ...

  4. Jabber/XMPP协议与架构

    一.概述 由Jeremie Miller于1998年开始这个项目.Jabber是一个开放源码形式组织产生的网络实时通信协议,第一个公开版本于2000年5月发行.Jabber已经由IETF XMPP协议 ...

  5. Solr与Mysql简单集成

    Solr与Mysql数据库的集成,实现全量索引.增量索引的创建. 基本原理很简单:在Solr项目中注册solr的DataImportHandler并配置Mysql数据源以及数据查询sql语句.当我们通 ...

  6. Winform使用DevExpress的WaitDialogForm画面 z

    使用了DevExpress的WaitDialogForm 在应用程序加载开始时新建一个线程,并将loading画面show起来,在应用程序画面弹出前将该线程终止. 代码: private DevExp ...

  7. setFocusable、setEnabled、setClickable区别

    setClickable  设置为true时,表明控件可以点击,如果为false,就不能点击:“点击”适用于鼠标.键盘按键.遥控器等:注意,setOnClickListener方法会默认把控件的set ...

  8. FOJ 1962 新击鼓传花游戏 线段树

    维护一个sum数组,有点划分树的思想,写过划分树的应该能看出来 #include<cstdio> #include<algorithm> #include<iostrea ...

  9. delegate 为什么用 weak属性

    weak指针主要用于“父-子”关系,父亲拥有一个儿子的strong指针,因此是儿子的所有者:但是为了阻止所有权回环,儿子需要使用weak指针指向父亲:你的viewcontroller通过strong指 ...

  10. 【windows核心编程】一个HOOK的例子

    一.应用场景 封装一个OCX控件,该控件的作用是来播放一个视频文件,需要在一个进程中放置四个控件实例. 由于控件是提供给别人用的,因此需要考虑很多东西. 二.考虑因素 1.控件的父窗口resize时需 ...