poj1584A Round Peg in a Ground Hole
题意甚是难懂!这是第二遍做这道题了,依旧无法理解题意,搜了下题意。。。
首先需要判断是不是为凸多边形。(从一个顶点走一遍即可,要注意顺逆时针,题目中没有指明)
其次看一下圆是不是能够放入多边形内。(首先判断一下圆心是否在圆内,然后枚举圆心到所有边的距离与半径r进行比较)
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 10000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
#define _sign(x) ((x) > eps?1:((x) < -eps ? 2 :0))
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
}p[N],ch[N];
int top;
struct Circle
{
Point c;
double r;
//Circle(Point c,double r):c(c),r(r){}
Point point (double a)
{
return Point(c.x+cos(a)*r,c.y+sin(a)*r);
}
};
typedef Point pointt;
pointt operator + (Point a,Point b)
{
return Point(a.x+b.x,a.y+b.y);
}
pointt operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
double cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
double mul(Point p0,Point p1,Point p2)
{
return cross(p1-p0,p2-p0);
}
double dis(Point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
//精度判正负
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
int Graham(int n)
{
int i,s[] = {,,};
double t;
for(i = ; i < n&&s[]|s[]; i ++)
{
t = mul(p[(i+)%n],p[(i+)%n],p[i]);
s[_sign(t)] = ;
}
return s[]|s[];
}
double distoline(Point p,Point a,Point b)
{
Point v1 = b-a,v2 = p-a;
return fabs(cross(v1,v2)/dis(v1));
}
int inside(Point po,int n)
{
int i,s[] = {,,};
double t;
for(i = ;i < n&&s[]|s[];i ++)
{
t = mul(p[(i+)%n],po,p[i]);
s[_sign(t)] = ;
}
return s[]|s[];
}
int main()
{
int n,i;
Circle cc;
while(scanf("%d",&n)!=EOF)
{
if(n<) break;
scanf("%lf%lf%lf",&cc.r,&cc.c.x,&cc.c.y);
for(i = ; i < n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
top = ;
int m = Graham(n);
if(!m)
{
puts("HOLE IS ILL-FORMED");
continue;
}
int flag = ;
if(!inside(cc.c,n))
{
puts("PEG WILL NOT FIT");
continue;
}
for(i = ; i < n; i ++)
{
if(dcmp(distoline(cc.c,p[i],p[i-])-cc.r)<)
{
flag = ;
break;
}
}
if(!flag)
puts("PEG WILL NOT FIT");
else
puts("PEG WILL FIT");
}
return ;
}
poj1584A Round Peg in a Ground Hole的更多相关文章
- A Round Peg in a Ground Hole(凸包应用POJ 1584)
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5684 Accepte ...
- POJ 1584 A Round Peg in a Ground Hole(判断凸多边形,点到线段距离,点在多边形内)
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4438 Acc ...
- POJ 1584 A Round Peg in a Ground Hole 判断凸多边形,判断点在凸多边形内
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5456 Acc ...
- POJ 1584 A Round Peg in a Ground Hole[判断凸包 点在多边形内]
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6682 Acc ...
- POJ 1518 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】
链接: http://poj.org/problem?id=1584 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 1584 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】
链接: http://poj.org/problem?id=1584 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 1584:A Round Peg in a Ground Hole
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5741 Acc ...
- POJ 1584 A Round Peg in a Ground Hole 判断凸多边形 点到线段距离 点在多边形内
首先判断是不是凸多边形 然后判断圆是否在凸多边形内 不知道给出的点是顺时针还是逆时针,所以用判断是否在多边形内的模板,不用是否在凸多边形内的模板 POJ 1584 A Round Peg in a G ...
- A Round Peg in a Ground Hole(判断是否是凸包,点是否在凸包内,圆与多边形的关系)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4628 Accepted: 1434 Description The D ...
随机推荐
- 23、jQuery九类选择器/jQuery常用Method-API/jQuery常用Event-API
1)掌握jQuery九类选择器及应用 2)掌握jQuery常用Method-API 3)掌握jQuery常用Event-API 一)jQuery九类选择器[参见jQueryAPI.chm手册] 目 ...
- Java Web Service 学习
参考原文: http://blog.csdn.net/ostrichmyself/article/details/6393627 http://www.cnblogs.com/Jessy/p/3528 ...
- 使用epel源安装依赖包时报错
[root@test_web1 ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch. ...
- python怎么装模块
windows下 最简单的方法: File---Settings--Project ---Project Interpreter 下----点击 +号,输入你需要安装的模块名,点击Install P ...
- rtc关机闹钟6 AlarmManagerService研究
这个是 private void setLocked(int type, long when) { if (mNativeData != 0) { // The kernel n ...
- [转]iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
转载地址:http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINav ...
- miniUI子窗口调父窗口方法
window.Owner.XXX 其中XXX是父窗口里的方法名
- easyui tab 关闭
<div id="mm" class="easyui-menu" style="width:150px;"> &l ...
- Session机制(是对cookie的作用的提升,使用较多)
1.Session作用类似于购物车,第一次,放入物品,可以获得Session的id,并可以设置id失效的时间,这样便于多次将物品放在购物车里面,使用的就是获取的Session的id: 2.Sessio ...
- uva 437,巴比伦塔
题目链接:https://uva.onlinejudge.org/external/4/437.pdf 题意:巴比伦塔: 给出n种立方体,一个立方体能放到另一个立方体上,必须满足,底面一定要小于下面的 ...