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 ...
随机推荐
- SQL Server 2005 日志文件过大处理
由于安装的时候没有计划好空间,默认装在系统盘,而且又没有做自动备份.截断事务日志等,很快LDF文件就达到十几G,或者几十G ,此时就不得不处理了. 备份和计划就不说了,现在就说下怎么把它先删除吧: 1 ...
- linux中的nm命令简介
转:http://blog.csdn.net/stpeace/article/details/47089585 一般来说, 搞linux开发的人, 才会用到nm命令, 非开发的人, 应该用不到. 虽然 ...
- Y2K Accounting Bug 分类: POJ 2015-06-16 16:55 14人阅读 评论(0) 收藏
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11222 Accepted: 56 ...
- ural 1104,暴力取模
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1104 题目大意:输入一个字符串(数字与大写字母组成),输出n,n满足此字符串为n进制时, ...
- Uva(10048),最短路Floyd
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- Android中的sharedUserId属性详解
在Android里面每个app都有一个唯一的linux user ID,则这样权限就被设置成该应用程序的文件只对该用户可见,只对该应用程序自身可见,而我们可以使他们对其他的应用程序可见,这会使我们用到 ...
- js取当前项目名称
function getContextPath(){ var path = window.location.href; path = path.substring(0, path.lastIndexO ...
- sql 邮件发送测试情况
sql 邮件发送测试情况 select * from msdb.dbo.sysmail_allitems select * from msdb.dbo.sysmail_event_log
- SpringMVC拦截器2(资源和权限管理)(作为补充说明)
SpringMVC拦截器(资源和权限管理) 1.DispatcherServlet SpringMVC具有统一的入口DispatcherServlet,所有的请求都通过DispatcherServle ...
- HDU2112 HDU Today 最短路+字符串哈希
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...