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 ...
随机推荐
- iOS 判断相机权限是否被限制,判断相机是否可以使用
判断相机权限是否被限制 需要导入 AVFoundation 类 [objc] view plain copy #import <AVFoundation/AVFoundation.h> ...
- 每日一九度之 题目1033:继续xxx定律
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5502 解决:1351 题目描述: 当n为3时,我们在验证xxx定律的过程中会得到一个序列,3,5,8,4,2,1,将3称为关键数, ...
- 动态规划(DP),模拟
题目链接:http://poj.org/problem?id=1088 Memory: 252KTime: 16MSLanguage: C++Result: Accepted 解题报告: 1.lm[i ...
- boost库学习之regex
一.背景 项目中许多地方需要对字符串进行匹配,比如根据指定的过滤字符串来过滤文件名.刚开始是排斥使用boost库的,第一,我不熟悉boost库:第二,如果引入第三方库,就会增加库的依赖,这样的后果是, ...
- libevent安装及使用
一.安装libevent 官网:http://libevent.org/ 选择最新版本下载,我选择的是libevent-2.0.22-stable.tar.gz,然后安装README文件中描述的方法编 ...
- Entity Framework 第四篇 优化SQL查询
Expression<Func<TEntity, bool>>与Func<TEntity, bool>的异同 public IList<TEntity> ...
- C#中的字符串处理——找出最长数字子串
百度测试部2015年10月份的面试题之——字符串处理,找出最长的子串. 代码如下: private static string SelectNumberFromString(string input) ...
- masonry插件和infinitescroll插件实现无刷新无分页完美瀑布流
地址有:http://www.17sucai.com/pins/2657.html 如果你善于发现美,如果你善于观察新鲜的事物,如果你是一名有爱的前端攻城师或设计尸,那么你一定不会对下面图片中的结构感 ...
- 2014江西理工大学C语言程序竞赛高级组
Beautiful Palindrome Number 题意:求N里面有多少个符合要求的数字(数字要求:回文数,且前一半部分是不严格递增) 解法:打表 #include<bits/stdc++. ...
- java实现按拼音排序名称
private static String[] nameArray = {"张三","李四","王二","付火"}; @ ...