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 ...
随机推荐
- CentOS Linux修改默认Bash shell为Zsh shell
Shell是在程序员与服务器间建立一个桥梁,它对外提供一系列命令,让我们得以控制服务器.常用的Bash就是Shell的一种,也是Linux下默认Shell程序.这里介绍一种更强大的.更人性化的Shel ...
- 普通帐号起redis
wget http://download.redis.io/releases/redis-4.0.11.tar.gz $ tar xzf redis-4.0.11.tar.gzmv redis-4.0 ...
- [Python3] 028 常用模块 datetime
目录 datetime 1. datetime.date 2. datetime.time 3. datetime.datetime 4. datetime.timedelta 补充 datetime ...
- React进阶篇学习
继续上一次基础篇, 分享一些关于React的进阶技术 React 进阶部分 ** context ** ** setState vs forceUpdate ** ** Mixins ** ** HO ...
- window对象open方法详解
window.open详解 window.open("sUrl","sName","sFeature","bReplace&quo ...
- 判断浏览器类型JS
// 判断浏览器类型 getExplorer() { var explorer = window.navigator.userAgent, compare = function (s) { retur ...
- Git 设置 用户名 和 邮箱
git config --global user.name "Vincent" git config --global user.email "********@qq.c ...
- 十一、LaTex中的矩阵
- 面向新手的Web服务器搭建(一)——IIS的搭建
很多童鞋说自己是做移动开发的,想挂个简单的Web API,可是服务器又不会搭,这样一来测试就成了问题.看看网上的教程,发现略难懂,而且大多是一个转一个,没价值,所以干脆写几篇文章讲讲简单的Web服务器 ...
- 爬虫获取网页数据,报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start by
https://blog.csdn.net/hj_xy_0705/article/details/85011072