POJ 1912 凸包
题目;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
const int mod=100000000; struct Point{
double x,y;
//Point(){};
Point(double xx=0,double yy=0):x(xx),y(yy){}
bool read()
{
return ~scanf("%lf%lf", &x, &y);
}
bool operator<(const Point p) const{
if(this->x!=p.x)
return this->x<p.x;
else return this->y<p.y;
}
double dot(Point p)
{
return this->x*p.x+this->y*p.y;
}
double getA()
{
double A=atan2(this->y,this->x);
if(A<-pi/2+eps) A+=2*pi;
return A;
}
Point operator-(Point p)
{
return Point(this->x-p.x,this->y-p.y);
}
}; double det(Point p,Point q)
{
return p.x*q.y-q.x*p.y;
} int dcmp(double x)
{
if(fabs(x)<eps) return 0;
else if(x>0) return 1;
else return -1;
}
Point p[100005],ans[100005];
double ang[100005]; int Convex_hull(Point *p,int n,Point *ans)
{
sort(p+1,p+n+1);
ans[1]=p[1];ans[2]=p[2];
int w=2;
for(int i=3;i<=n;i++)
{
int k=dcmp(det(p[i]-ans[w-1],ans[w]-ans[w-1]));
while(dcmp(det(p[i]-ans[w-1],ans[w]-ans[w-1]))>0&&w>=2)
w--;
ans[++w]=p[i];
}
int cur=w;
ans[++w]=p[n-1];
for(int i=n-2;i>=2;i--)
{
int k=dcmp(det(p[i]-ans[w-1],ans[w]-ans[w-1]));
while(dcmp(det(p[i]-ans[w-1],ans[w]-ans[w-1]))>0&&w>=cur+1)
w--;
ans[++w]=p[i];
}
return w;
} int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++) p[i].read();
int m=0;
if(n>1) {m=Convex_hull(p,n,ans);}
ans[m+1]=ans[0];
for(int i=1;i<=m;i++)
ang[i]=(ans[i+1]-ans[i]).getA();
Point q[3];
while(q[1].read())
{
q[2].read();
int i=upper_bound(ang+1,ang+m+1,(q[2]-q[1]).getA())-ang;
int j=upper_bound(ang+1,ang+m+1,(q[1]-q[2]).getA())-ang;
if(n>1&&dcmp(det(q[2]-q[1],ans[i]-q[1]))*dcmp(det(q[2]-q[1],ans[j]-q[1]))<0)
printf("BAD\n");
else printf("GOOD\n");
}
}
return 0;
}
POJ 1912 凸包的更多相关文章
- poj 1873 凸包+枚举
The Fortified Forest Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6198 Accepted: 1 ...
- poj 1113 凸包周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33888 Accepted: 11544 Descriptio ...
- Poj 2187 凸包模板求解
Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...
- POJ 1912 A highway and the seven dwarfs (凸包)
[题目链接] http://poj.org/problem?id=1912 [题目大意] 给出一些点,表示一些屋子,这些屋子共同组成了村庄,现在要建一些高速公路 问是否经过了村庄. [题解] 这些屋子 ...
- poj 3348--Cows(凸包求面积)
链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: ...
- poj 1228 凸包
题目链接:http://poj.org/problem?id=1228 #include<cstdio> #include<cstring> #include<cmath ...
- poj 2187 凸包加旋转卡壳算法
题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...
- POJ 3608 凸包间最短距离(旋转卡壳)
Bridge Across Islands Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11539 Accepted: ...
- POJ 1113 凸包模板题
上模板. #include <cstdio> #include <cstring> #include <iostream> #include <algorit ...
随机推荐
- ArrayList(顺序表)和LinkedList(链表)的区别联系,优劣取舍问题
ArrayList和LinkedList都是List接口的实现类.主要区别如下: 最主要的区别是底层的数据结构不同: 1)ArrayList相当于一个动态数组,需要随机访问列表中的元素时,ArrayL ...
- [Python3] 026 常用模块 calendar
目录 calendar 1. calendar.calendar(year, w, l, c, m) 2. calendar.prcal(year, w, l, c, m) 3. calendar.m ...
- 【转帖】UDIMM、RDIMM、SODIMM以及LRDIMM的区别
转载自http://www.sohu.com/a/165343889_781333. DIMM简介 DIMM(Dual Inline Memory Module,双列直插内存模块)与SIMM(sing ...
- 关于eclipse设置JRebel
版本:eclipse ee Version: 2018-09 (4.9.0) jrebel:最新2019-2 1.在eclipse->help->eclipse Marketplace 2 ...
- 均值滤波器(平滑空间滤波器)基本原理及Python实现
1. 基本原理 使用元素的领域内像素的平均值代替该元素,可明显的降低图像灰度的尖锐变换.它的一种重要应用是模糊处理:得到感兴趣的区域的粗略表示,将次要的/小的元素与背景融合,使得主要的/较大的元素变得 ...
- [LeetCode] 228. 汇总区间
题目链接: https://leetcode-cn.com/problems/summary-ranges 难度:中等 通过率:48.9% 题目描述: 给定一个无重复元素的有序整数数组,返回数组区间范 ...
- python 利用 smtplib发邮件
import smtplib from email.mime.text import MIMEText title = "request build error" content ...
- c#EntityFrameworkcodeFirst模式
一.首先定义数据类 [DataContract(Namespace="http://www.cninnovation.com/Services/2012")] public cl ...
- pip 安装超时解决方案
已经使用梯子,安装某依赖时仍然超时. 首先检查pip的版本是否需要更新,如果不是最新版本运行命令更新: python -m pip install --upgrade pip 如果仍然超时错误,则运行 ...
- matlab读取内容为二进制的TXT文件
本方法同样适合读取十六进制和二进制以外的其他进制文件,txt使用一个最简单的命令就可以读取 textread 这是一个十分有用,简便的函数(对于fopen fscanf而言)读取二进制txt文件:假如 ...