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 ...
随机推荐
- swoft| 源码解读系列二: 启动阶段, swoft 都干了些啥?
date: 2018-8-01 14:22:17title: swoft| 源码解读系列二: 启动阶段, swoft 都干了些啥?description: 阅读 sowft 框架源码, 了解 sowf ...
- codechef营养题 第二弹
第二弾が始まる! codechef problems 第二弹 一.Backup Functions 题面 One unavoidable problem with running a restaura ...
- 最短网络 Agri-Net
题目背景 农民约翰被选为他们镇的镇长!他其中一个竞选承诺就是在镇上建立起互联网,并连接到所有的农场.当然,他需要你的帮助. 题目描述 约翰已经给他的农场安排了一条高速的网络线路,他想把这条线路共享给其 ...
- [USACO09JAN]全流Total Flow
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...
- codevs3411 洪水
题目描述 Description 小浣熊松松和朋友到野外露营,没想到遇上了π年一次的大洪水,好在松松是一只爱观察的小浣熊,他发现露营地的地形和洪水有如下性质: ①露营地可以被看做是一个N*M的矩形方阵 ...
- ojdbc.jar
Oracle的jdbc驱动是ojdbc.jar 文件,那么mysql的jdbc驱动是什么呢? 匿名 | 浏览 689 次 发布于2015-06-07 02:06 最佳答案 MySQL的JDBC ...
- 条款50: 提高对C++的认识
class Base { public: virtual void f(int x); }; class Derived: public Base { public: virtual void f(d ...
- [Vue @Component] Pass Props Between Components with Vue Slot Scope & renderless component
Components with slots can expose their data by passing it into the slot and exposing the data using ...
- 躁动不安的const
就是用来恐吓你的 我能想到的,最短的.且const最多的一个语句是: int const * fun(int const*const a[],const int index)const; 而这个语句还 ...
- Python3基础(二) 基本数据类型
Python中的变量不需要声明.每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建.在Python中,变量就是变量,它没有类型,我们所说的"类型"是变量所指的内存中对象的类型 ...