Codeforces Gym 100338B Geometry Problem 计算几何
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
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 计算几何的更多相关文章
- Codeforces Gym 100338B Spam Filter 字符串哈希+贝叶斯公式
原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...
- Hdu-6242 2017CCPC-哈尔滨站 M.Geometry Problem 计算几何 随机
题面 题意:给你n个点,让你找到一个圆,输出圆心,和半径,使得有超过一半的点刚好在圆上.n<=1e5,题目保证了有解 题解:刚开始看着很不可做的样子,但是多想想,三点确定一个圆,三点啊! 现在有 ...
- 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 ...
- 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 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 ...
- 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 ...
- CodeForces 689E Mike and Geometry Problem (离散化+组合数)
Mike and Geometry Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/I Description M ...
- 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 ...
- HDU1086 You can Solve a Geometry Problem too(计算几何)
You can Solve a Geometry Problem too Time Limit: 2000/1000 M ...
随机推荐
- ByteBuffer用法小结
在NIO中,数据的读写操作始终是与缓冲区相关联的.读取时信道(SocketChannel)将数据读入缓冲区,写入时首先要将发送的数据按顺序填入缓冲区.缓冲区是定长的,基本上它只是一个列表,它的所有元素 ...
- Iwpriv工作流程及常用命令使用
iwpriv工具通过ioctl动态获取相应无线网卡驱动的private_args所有扩展参数 iwpriv是处理下面的wlan_private_args的所有扩展命令,iwpriv的实现上,是这样的, ...
- 【转】使用NetBeans和Eclipse开发PHP应用程序
[51CTO独家特稿]各位用户如果单独看NetBeans和Eclipse的市场占有率,你可能会认为使用其中任何一种IDE开发PHP应用程序都没有 问题,例如: 1.NetBeans:一款开源的集成开发 ...
- codeforces 679A Bear and Prime 100 交互
第一次交互题,记录一下吧 #include <cstdio> #include <iostream> #include <ctime> #include <v ...
- RockMongo安装使用笔记
下载nginx最新版本下载PHP,5.X版本即可,非线程安全的的,因为nginx用的是fastcgi下载rockmongo最新版本下载php_mongo组件 在rockmongo里的readme里有下 ...
- 浏览器URL传参最大长度问题
这几天为解决一个BUG头疼了一段时间,BUG现象如下: 一个选择人员的选择控件,当选择多个人时(50多个的时候),返回没有错误现象,而再一次打开的时候就报404错误.看到这个错误非常纳闷,无法下手,只 ...
- QT-【转】Qt 4迁移至Qt 5
将Qt 4代码迁移到Qt 5还是比较简单的.实际上,在Qt 5开发过程中就已经注意了与Qt 4代码保持兼容性. 与Qt 3到Qt 4的迁移不同,Qt 5的核心类库并没有做大的API的修改,只有几个新的 ...
- bfs CCF2016第七次 游戏
// bfs CCF2016第七次 游戏 // 思路: // O(300*100*100) // 直接暴搜 // 注意,同一格同一时间不能经过两次!!! #include <bits/stdc+ ...
- SQL游标遍历数据表
DECLARE @资产编号 VARCHAR(50) ,@gsid VARCHAR(50) DECLARE test_Cursor CURSOR LOCAL FOR SELECT 资产编号,gsid F ...
- 百度,你家云管家能靠谱点不?替你脸红!Shame on you!
此文已提交百度云问题反馈, 坐等答复. 笔者最近下载某24+G分卷压缩文件, 24+G啊, 足足要下将近7个小时.满心欢喜的下载完却尼玛发现解压出错, 有6个文件无法解压?wrong password ...