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 ...
随机推荐
- 【转】cocos2d-x 3.2 Fast TileMap
概述 在游戏中常常会有丰富的背景元素,如果直接使用大的背景图实现,这会造成资源浪费.TileMap就是为了解决这问题而产生的.Cocos2d-x支持使用Tile地图编辑器创建的TMX格式的地图. Co ...
- Android 项目利用 Android Studio 和 Gradle 打包多版本APK
在项目开发过程中,经常会有需要打包不同版本的 APK 的需求. 比如 debug版,release版,dev版等等. 有时候不同的版本中使用到的不同的服务端api域名也不相同. 比如 debug_ap ...
- window.history
作者:zccst 旧版: forword() backword() go(number) HTML5中新增了 onhashchange 浏览器兼容性较好,用得较多 pushState / repla ...
- linux中waitpid及wait的用法
wait(等待子进程中断或结束) 表头文件 #include<sys/types.h> #include<sys/wait.h> 定义函数 pid_t wa ...
- IO负载高的来源定位
前言: 在一般运维工作中经常会遇到这么一个场景,服务器的IO负载很高(iostat中的util),但是无法快速的定位到IO负载的来源进程和来源文件导致无法进行相应的策略来解决问题. 这个现象在MySQ ...
- 【转】SDP file
SDP file Introduction The Session Description Protocol (SDP) is a format for describing the initiali ...
- SQL注入中利用XP_cmdshell提权的用法(转)
先来介绍一下子服务器的基本情况,windows 2000 adv server 中文版,据称 打过了sp3,asp+iis+mssql .首先扫描了一下子端口,呵呵,开始的一般步骤. 端口21开放: ...
- 分享一个Web弹框类
using System; using System.Text; namespace Core { /// <summary> /// MessageBox 的摘要说明. /// < ...
- 利用原生JavaScript获取样式的方式小结
来源:http://www.ido321.com/930.html ps:是获取样式,不是设置样式.若没有给元素设置样式值,则返回浏览器给予的默认值.(论坛整理) 1.element.style:只能 ...
- jQuery-validate error messages in Twitter ...
http://www.jefclaes.be/2012/11/jquery-validate-error-messages-in.html something satisfactory. In thi ...