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 ...
随机推荐
- 字符串转Interger
public static void main(String[] args) { String t = "5"; Integer integer = Integer.valueOf ...
- spring boot-2.Hello world
由于 个人习惯,我选择使用STS来作为开发工具.跳过手动构建spring boot 项目的环节,直接使用向导创建spring boot 项目. 1.创建spring boot项目 File ----& ...
- [转帖]数据库默认驱动、URL、端口
超详细的各种数据库默认驱动.URL.端口总结 http://database.51cto.com/art/201906/598043.htm 学习了解一下. 概述 今天主要对各种数据库默认端口和UR ...
- Python常用方法库备忘(一)_当前路径下文件夹和文件
#!/usr/bin/env python # -*- coding:utf-8 -*- # --------------*-------------- # @Author : AilF # @Tim ...
- memset函数及注意事项
memset函数的原型为:void * memset(void *ptr,int value,size_t num);用于为地址ptr开始的num个字节赋值value. memset函数的头文件为:C ...
- numpy将数组保存为文件
保存单个数组 np.save和np.load是读写磁盘数组数据的两个主要函数.默认情况下,数组是以未压缩的原始二进制格式保存在扩展名为.npy的文件中的: 如果文件路径末尾没有扩展名.npy,则该扩展 ...
- array_chunk的用法和php操作大数据
一.array_chunk() 函数 二.php操作大数据 1.在操作大数量数据与数据库交互时,比如插入大量数据,db就会报错,这时可以把原本的数据用array_chunk分隔成几个数组块,再循环插入 ...
- Bug快到碗里来
Bug快到碗里来 python错误--'list' object is not callable 原因及解决方法1 你定义了一个变量的变量名和系统自带的关键字冲突,调用变量时关键字被传到调用的位置,就 ...
- tarjan算法求无向图的桥、边双连通分量并缩点
// tarjan算法求无向图的桥.边双连通分量并缩点 #include<iostream> #include<cstdio> #include<cstring> ...
- css3 伪类以及伪元素的特效
菱形