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. 【大数取模】HDOJ-1134、CODEUP-1086

    1086: 大数取模   题目描述 现给你两个正整数A和B,请你计算A mod B.为了使问题简单,保证B小于100000. 输入 输入包含多组测试数据.每行输入包含两个正整数A和B.A的长度不超过1 ...

  2. 简单易用的AOP/IOC框架

    Source: http://www.codeproject.com/KB/Articles/684613/Working/AopIoc.zip Introduction Supper framewo ...

  3. 【html】页面制作规范文档

    每天都在写html/css/js代码,总结的一些页面制作的规范 文件命名规范 1) 文件目录.文件名称统一用小写的英文字母.数字.下划线组合,文件名要与表现的内容相近,不到万不得已不要以拼音作为名称, ...

  4. ubuntu1204上不能正常用emacs配合gocode进行自动补全

    我按gocode的页面https://github.com/nsf/gocode上去做,可是还是未成功,,我确认auto-complete在c-mode中是可以使用的,因为有补全出来了, 我再找了ht ...

  5. 【转】使用NetBeans和Eclipse开发PHP应用程序

    [51CTO独家特稿]各位用户如果单独看NetBeans和Eclipse的市场占有率,你可能会认为使用其中任何一种IDE开发PHP应用程序都没有 问题,例如: 1.NetBeans:一款开源的集成开发 ...

  6. POJ 1860 Currency Exchange

    题意:有n种货币,可以互相兑换,有m个兑换规则,兑换规则给出汇率r和手续费c,公式为b = (a - c) * r,从a货币兑换为b货币,问能不能通过不断的兑换赚钱,兑换期间手中的钱数不可以为负. 解 ...

  7. 浅析基层检察院派驻乡镇检察室的健康发展 z

    时间:2011-03-22 10:08 作者:祝志方 新闻来源:正义网 一.前言 在我国,基层检察院派驻乡镇检察室的发展经过了一个曲折发展的历程,上世纪80年代,随着经济社会的发展,一批乡镇检察室应运 ...

  8. Nginx下防御HTTP GET FLOOD(CC)攻击

    Nginx下防御HTTP GET FLOOD(CC)攻击 Nginx是一款轻量级的Web服务器,由俄罗斯的程序设计师Igor Sysoev所开发,最初供俄国大型的入口网站及搜寻引Rambler使用. ...

  9. webdriver(python)学习笔记七——多层框架定位与智能等待

    多层框架或窗口定位: switch_to_frame() switch_to_window() 智能等待: implicitly_wait() 现在web应用中经常会遇到框架如(frame)或窗口(w ...

  10. python中List的sort方法的用法

    python列表排序 简单记一下python中List的sort方法(或者sorted内建函数)的用法. 关键字: python列表排序 python字典排序 sorted List的元素可以是各种东 ...