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 ...
随机推荐
- ectouch第二讲之 文件结构
相信大家在ectouch官网都注意到了,ectouch采用的MVC框架,之前一直以为它用的和ecshop一样都是smarty,本鸟默默按照smarty的文件结构研究了好几天,结果是各种文件对不上号.无 ...
- 约瑟夫问题 java
约瑟夫环:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围.从编号为k的人开始报数,数到m的那个人出列;他的下一个人又从1开始报数,数到m的那个人又出列;依此规律重复下去,直到圆桌周围 ...
- HDU:Integer Inquiry
#include"stdio.h" #include"stdlib.h" #include"string.h" #define N 105 ...
- hihoCoder 数论五·欧拉函数
题目1 : 数论五·欧拉函数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho有时候会用密码写信来互相联系,他们用了一个很大的数当做密钥.小Hi和小Ho约定 ...
- C#之参数线程
public Form1() { InitializeComponent(); } Thread t; private void button1_Click(object sender, EventA ...
- wpfのpack协议
当引用的资源需要做成dll时,要用此协议 协议:pack:// 授权:有两种.一种用于访问编译时已经知道的文件,用application:///.一种用于访问编译时不知道.运行时才知道的文件 ...
- Mysql-学习笔记(==》集合函数与分组四)
-- 聚集函数 配合分组语句 group by-- 显示最高分SELECT MAX(sscore) FROM db.`student`;-- 显示最高分学生的信息min maxSELECT * FRO ...
- 2016年12月10日 星期六 --出埃及记 Exodus 21:5
2016年12月10日 星期六 --出埃及记 Exodus 21:5 "But if the servant declares, `I love my master and my wife ...
- 推荐一款非常棒的谷歌插件---快速查看HTML页面元素的CSS样式
一.下载地址 http://chromecj.com/web-development/2015-05/456/download.html 二.简介 CssViewer是一款快速查看当前页面元素的CSS ...
- linux下的文件系统
转http://www.cnblogs.com/yyyyy5101/articles/1901842.html 谈谈个人对于文件系统的认识,其实这也体现了计算机操作系统的抽象:你不用管计算机中的文件如 ...