POJ 1584 计算几何
思路:
求一遍凸包
用三角形面积(叉积求一下)/边长
求出来高,跟半径比一比
坑点:凸包上三点共线
//By SiriusRen
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define eps 1e-9
const int N=;
int n,top,k,f;double r;
struct Point{double x,y;}point[N],tubao[N],cir;
Point operator-(Point a,Point b){Point c;c.x=a.x-b.x,c.y=a.y-b.y;return c;}
bool operator<(Point a,Point b){return abs(a.x-b.x)<eps?a.y<b.y:a.x<b.x;}
double chaji(Point a,Point b){return a.x*b.y-a.y*b.x;}
double cross(Point a,Point b,Point c){return chaji(a-c,b-c);}
double dis(Point a){return sqrt(a.x*a.x+a.y*a.y);}
bool check(Point a,Point b){return abs(chaji(a-cir,b-cir))/dis(a-b)>r-eps;}
int main(){
while(scanf("%d",&n)){
if(n<)break;top=f=;
scanf("%lf%lf%lf",&r,&cir.x,&cir.y);
for(int i=;i<=n;i++)scanf("%lf%lf",&point[i].x,&point[i].y);
sort(point+,point++n);
for(int i=;i<=n;i++){
while(top>&&cross(tubao[top],point[i],tubao[top-])<-eps)top--;
tubao[++top]=point[i];
}k=top;
for(int i=n-;i;i--){
while(top>k&&cross(tubao[top],point[i],tubao[top-])<-eps)top--;
tubao[++top]=point[i];
}
if(top!=n+){puts("HOLE IS ILL-FORMED");continue;}
for(int i=;i<=n;i++)if(!check(tubao[i],tubao[i+]))f=;
for(int i=;i<=n;i++)
if(chaji(tubao[i+]-tubao[i],cir-tubao[i])<)f=;
printf("PEG WILL %sFIT\n",f?"NOT ":"");
}
}
POJ 1584 计算几何的更多相关文章
- POJ 1584 A Round Peg in a Ground Hole 判断凸多边形 点到线段距离 点在多边形内
首先判断是不是凸多边形 然后判断圆是否在凸多边形内 不知道给出的点是顺时针还是逆时针,所以用判断是否在多边形内的模板,不用是否在凸多边形内的模板 POJ 1584 A Round Peg in a G ...
- 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 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6238 Acc ...
- POJ - 1584 A Round Peg in a Ground Hole(判断凸多边形,点到线段距离,点在多边形内)
http://poj.org/problem?id=1584 题意 按照顺时针或逆时针方向输入一个n边形的顶点坐标集,先判断这个n边形是否为凸包. 再给定一个圆形(圆心坐标和半径),判断这个圆是否完全 ...
- POJ 1556 计算几何+最短路
代码1: #include<iostream> #include<stdio.h> #include<string> #include<string.h> ...
- POJ 2954-Triangle(计算几何+皮克定理)
职务地址:POJ 2954 意甲冠军:三个顶点的三角形,给出,内部需求格点数. 思考:就像POJ 1265. #include <stdio.h> #include <math.h& ...
- POJ 1584 A Round Peg in a Ground Hole --判定点在形内形外形上
题意: 给一个圆和一个多边形,多边形点可能按顺时针给出,也可能按逆时针给出,先判断多边形是否为凸包,再判断圆是否在凸包内. 解法: 先判是否为凸包,沿着i=0~n,先得出初始方向dir,dir=1为逆 ...
- 简单几何(点的位置) POJ 1584 A Round Peg in a Ground Hole
题目传送门 题意:判断给定的多边形是否为凸的,peg(pig?)是否在多边形内,且以其为圆心的圆不超出多边形(擦着边也不行). 分析:判断凸多边形就用凸包,看看点集的个数是否为n.在多边形内用叉积方向 ...
- 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 ...
随机推荐
- 07 Python编码问题
17) 编码 18) Python3的执行过程 19) 常见编码错误原因 20) 后附一部分编码详细信息(个人总结,有误望指正) 想了解Python3的编码更细致的讲解请参考大王的文章 http:// ...
- 九九乘法表-Java
public class Test1 { public static void main(String[] args){ for(int i=1;i<=9;i++){ for(int j=1;j ...
- Windows窗口创建的具体步骤
/*实现窗口创建的六步骤:第一步:创建入口函数WinMain第二步:注册窗口类第三部:实现回调函数的功能第四步:显示窗口第五步:更新窗口第六步:消息循环*/ #include "stdafx ...
- 阿里云服务器Ubuntu 16.04 3安装mysql
.更新系统 apt-get update [注意:要在root用户下] .安装mysql-server apt-get install mysql-serverapt-get install mysq ...
- Java基础学习总结(81)——如何尽可能的减少Java代码中bug
Java编程语言的人气自然无需质疑,从Web应用到Android应用,这款语言已经被广泛用于开发各类应用及代码中的复杂功能. 不过在编写代码时,bug永远是困扰每一位从业者的头号难题.在今天的文章中, ...
- java中split以。点和|分割的问题
问题:想要按照点来切分字符串直接这样 String[] filep=filename.split("."); 结果得到一个空数组 解决方法: 法一:需要转义,改为:(注意是2个\\ ...
- linux下安装并配置vim
1.安装:sudo apt-get install vim-gtk 安装好后vim,并按“tab”键,可以看到vim的存在,则安装好2.设置更加人性化:sudo vim /etc/vim/vimrc ...
- cpus Vs cpu period and cpu quota
1. https://docs.oracle.com/cd/E37670_01/E75728/html/section-zb1_wqw_gt.html To control a container' ...
- Workflow:添加工作流存储功能
数据库准备: 1. 创建database(这里我们用的是MSSQL.Workflow支持其它数据库,但是MSSQL是配置最方便,不要问我为什么!). 2. 运行位于[%WINDIR%\Microsof ...
- Android中相机拍照
Android中调用系统相机的api接口在android.hardware包中.包里面类主要用到了Camera类.该类里面包含几个内部类:Camera.Parameters.Camera.Camera ...