POJ 1584 A Round Peg in a Ground Hole (凸包的判断+点在凸包+圆在凸包内)
来源:互联网 发布:sql select 临时表 编辑:程序博客网 时间:2024/06/06 01:07
大意:给定多边形的点和圆的半径长,和原点。进行凸包的判断+点在凸包+圆在凸包内的判断。
#include<map>#include<cmath>#include<queue>#include<cmath>#include<cstdio>#include<stack>#include<iostream>#include<cstring>#include<algorithm>#define inf 999999999.9#define eps 1e-8#define ls l,mid,rt<<1#define rs mid+1,rt,rt<<1|1#define LL __int64#define _sign(x) ((x)>eps?1:( (x)<-eps?2:0 ) )using namespace std;struct point{ double x,y;};struct Circle{ double r; point poi;}c;struct Line{ double a,b,c;};double xmult(point p1,point p2,point p){ return (p1.x - p.x)*(p2.y-p.y) - (p2.x - p.x)*(p1.y - p.y);}int checkvex(int n,point *p){//多边形的判断 int s[3]={1,1,1}; for(int i = 0;i < n&&s[1]|s[2];++ i) s[_sign(xmult(p[(i+1)%n],p[(i+2)%n],p[i]))] = 0; return s[1] | s[2];}bool insideConvex(point q,int n,point *p){//点在多边形内的判断 int s[3] ={1,1,1}; for(int i = 0;i < n &&s[1] | s[2];++ i ) s[_sign(xmult(p[(i+1)%n ],q,p[i]))] = 0; return s[1]|s[2];}Line towpoLine(point p1,point p2){ //两点连城的线 Line l; l.a = p1.y - p2.y; l.b = p2.x - p1.x; l.c = p1.x*p2.y - p2.x*p1.y; return l;}double potoLine(point p,Line l){//点到直线的距离 return fabs(l.a*p.x+l.b*p.y+l.c)/sqrt(l.a*l.a+l.b*l.b);}point q[10010];int main(){ int n,i,j,k; while(~scanf("%d",&n),n>2){ scanf("%lf%lf%lf",&c.r,&c.poi.x,&c.poi.y); for(i = 0;i < n;++ i) scanf("%lf%lf",&q[i].x,&q[i].y); if(checkvex(n,q)){//判断在多边形上 if(insideConvex(c.poi,n,q)){//圆心在多边形内 for(i = 0;i < n;++ i){ Line l = towpoLine(q[i],q[(i+1)%n]); if(potoLine(c.poi,l) - c.r <0 ){//不知道为什么< eps就错 printf("PEG WILL NOT FIT\n"); break; } } if(i == n) printf("PEG WILL FIT\n"); } else printf("PEG WILL NOT FIT\n"); } else printf("HOLE IS ILL-FORMED\n"); } return 0;}
0 0
- POJ 1584 A Round Peg in a Ground Hole (凸包的判断+点在凸包+圆在凸包内)
- POJ 1584 A Round Peg in a Ground Hole(是否凸包 && 圆是否在凸包内)
- POJ 1584 A Round Peg in a Ground Hole(凸包判定&&圆在凸包内判定)
- POJ1584-A Round Peg in a Ground Hole(凸包,判圆在凸包内)
- poj_1584 A Round Peg in a Ground Hole(凸包判断凸多边形+判断点在多边形内)
- poj1584--A Round Peg in a Ground Hole(判断凸包,并且判断圆是否在凸包内)
- poj 1584A Round Peg in a Ground Hole(计算几何 判断凸包)
- POJ A Round Peg in a Ground Hole <凸包判断以及点与多边形的相对位置>
- POJ 1584-A Round Peg in a Ground Hole(计算几何-凸包、点到线段距离)
- poj 1584 A Round Peg in a Ground Hole(判断凸多边形+圆是否在凸多边形内)
- POJ 1584:A Round Peg in a Ground Hole _判断点是否在多边形内(5种方法)
- A Round Peg in a Ground Hole(凸包应用POJ 1584)
- POJ 1584 A Round Peg in a Ground Hole(判断凸多边形,判断圆是否在凸多边形内)
- POJ 1584 A Round Peg in a Ground Hole 圆是否包含在凸包内
- 【POJ 1584】 A Round Peg in a Ground Hole (判凸包+判圆在凸包内)
- POJ 1584 A Round Peg in a Ground Hole(判断是否是凸包以及圆是否完全在凸包内)
- POJ 1584 A Round Peg in a Ground Hole(凸包判定,多边形计算与判定)
- POJ 1584 A Round Peg in a Ground Hole(凸多边形判断+点与多边形的位置关系)
- 【ZOJ 2042】Divisibility
- android视图学习---从源码角度来理解onMeasure过程
- 关于servlet和Javabean的学习笔记
- ios开发之即时通讯socket(AsyncSocket)
- hdoj 1434 幸福列车 【优先队列】
- POJ 1584 A Round Peg in a Ground Hole (凸包的判断+点在凸包+圆在凸包内)
- Android开发——自动连接指定SSID的wifi热点(不加密/加密)
- 2015总结
- storyboard 切圆
- 北京集训队 2016 Day4 alarm
- Android Camera怎样打开关闭闪光灯
- 线性表的应用3(单链表的基本实现和逆置)
- java实现图的最短路径(SP)的迪杰斯特拉(Dijkstra)算法
- Android开发之数组类的面试题目,android工程师java程序员必备