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 ...
随机推荐
- 实验1“C语言开发环境使用和数据类型、运算符、表达式”总结与体会
一.实验结论 1.判断奇偶 // 程序功能: // 要求用户从键盘输入一个整数,判断其是奇数还是偶数 #include <stdio.h> int main() { int x; prin ...
- 【18】AngularJS 包含
AngularJS 包含 在 AngularJS 中,你可以在 HTML 中包含 HTML 文件. 在 HTML 中包含 HTML 文件 在 HTML 中,目前还不支持包含 HTML 文件的功能. 服 ...
- Introduction to TensorFlow
Lecture note 1: Introduction to TensorFlow Why TensorFlow TensorFlow was originally created by resea ...
- HDU 2604 矩阵快速幂
题目大意 给定长度为l的只有f,m两种字母 的序列,问不出现fff,fmf的序列个数有多少个 每次的下一个状态都与前一次状态的后两个字母有关 比如我令mm : 0 , mf : 1 , fm : 2 ...
- [BZOJ1045][HAOI2008]糖果传递(数学分析)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1045 分析:均分纸牌的环状版本. 先看线性的版本: 设f[i]表示第I位从第i+1位得 ...
- NIO基础学习——缓冲区
NIO是对I/O处理的进一步抽象,包含了I/O的基础概念.我是基于网上博友的博客和Ron Hitchens写的<JAVA NIO>来学习的. NIO的三大核心内容:缓冲区,通道,选择器. ...
- [转] MySQL "replace into" 的坑 (5.5 ROW格式)
MySQL 对 SQL 有很多扩展,有些用起来很方便,但有一些被误用之后会有性能问题,还会有一些意料之外的副作用,比如 REPLACE INTO. 比如有这样一张表: 1 2 3 4 5 6 7 8 ...
- pt工具加字段脚本
#!/bin/bashcnn_db=$1table=$2alter_conment=$3 cnn_host='192.168.10.14'cnn_user='root'cnn_pwd='123456' ...
- Oracle Multitenant Environment (四) Create One or More CDBs
Using the CREATE DATABASE Statement to Create a CDB This section describes creating a CDB using the ...
- 创建SharePoint 2010 Timer Job
好久没有写博客了. 近期在使用SharePoint 2010中Timer Job的功能,有了一点心得,分享一下. 我个人觉得SharePoint Timer Job和Windows Service或者 ...