题目描述:

vjudge

POJ

题解:

半平面交判核的存在性。

重点在于一个点的核也算核

这样的话普通的求多边形的版本就要加一个特判。

就是把剩下的一个节点暴力带回所有直线重判,这时判叉积是否$\leq 0$,而不是$<0$。

好人一生平安

代码:

#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
const double eps = 1e-;
int dcmp(double x)
{
if(fabs(x)<=eps)return ;
return x>?:-;
}
struct Point
{
double x,y;
Point(){}
Point(double x,double y):x(x),y(y){}
Point operator + (const Point&a)const{return Point(x+a.x,y+a.y);}
Point operator - (const Point&a)const{return Point(x-a.x,y-a.y);}
Point operator * (const double&a)const{return Point(x*a,y*a);}
double operator ^ (const Point&a)const{return x*a.y-y*a.x;}
};
typedef Point Vector;
typedef vector<Point> Pol;
double ang(const Vector&v){return atan2(v.x,v.y);}
struct Line
{
Point p;
Vector v;
Line(){}
Line(Point p,Vector v):p(p),v(v){}
bool operator < (const Line&a)const
{
return ang(v)<ang(a.v);
}
};
bool Onleft(Line a,Point p)
{
return dcmp((a.v^(p-a.p)))>;
}
bool onleft(Line a,Point p)
{
return dcmp((a.v^(p-a.p)))>=;
}
Point L_L(Line a,Line b)
{
double t = ((b.p-a.p)^b.v)/(a.v^b.v);
return a.p+a.v*t;
}
int T,n;
Point p[N],tp[N];
Line s[N],ts[N];
int bpmj()
{
memset(ts,,sizeof(ts));memset(tp,,sizeof(tp));
sort(s+,s++n);
int hd,tl;
ts[hd=tl=]=s[];
for(int i=;i<=n;i++)
{
while(hd<tl&&!Onleft(s[i],tp[tl-]))tl--;
while(hd<tl&&!Onleft(s[i],tp[hd]))hd++;
ts[++tl] = s[i];
if(!dcmp(ts[tl].v^ts[tl-].v))
{
tl--;
if(Onleft(ts[tl],s[i].p))ts[tl]=s[i];
}
if(hd<tl)tp[tl-] = L_L(ts[tl-],ts[tl]);
}
while(hd<tl&&!Onleft(ts[hd],tp[tl-]))tl--;
if(hd==tl)
{
Point now = tp[hd];
for(int i=;i<=n;i++)
if(!onleft(s[i],now))
return ;
}
return ;
}
void build1()
{
for(int i=;i<n;i++)s[i]=Line(p[i],p[i+]-p[i]);
s[n] = Line(p[n],p[]-p[n]);
}
void build2()
{
for(int i=,j=n;i<j;i++,j--)swap(p[i],p[j]);
for(int i=;i<n;i++)s[i]=Line(p[i],p[i+]-p[i]);
s[n] = Line(p[n],p[]-p[n]);
}
void work()
{
scanf("%d",&n);int ans = ;
for(int i=;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
build1();
ans|=bpmj();
build2();
ans|=bpmj();
if(ans)puts("YES");
else puts("NO");
}
int main()
{
// freopen("tt.in","r",stdin);
scanf("%d",&T);
while(T--)work();
return ;
}

poj3335 Rotating Scoreboard的更多相关文章

  1. 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard

    山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...

  2. 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)

    Rotating Scoreboard Description This year, ACM/ICPC World finals will be held in a hall in form of a ...

  3. poj 3335 Rotating Scoreboard - 半平面交

    /* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...

  4. poj 3335 Rotating Scoreboard(半平面交)

    Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 25 ...

  5. POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)

    题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...

  6. poj 3335 Rotating Scoreboard (Half Plane Intersection)

    3335 -- Rotating Scoreboard 给出一个多边形,要求判断它的内核是否存在. 还是半平面交的题,在这道题中,公告板允许其所在位置与直线共线也算是可见,于是我们就可以将每一条直线微 ...

  7. POJ3335:Rotating Scoreboard——题解

    http://poj.org/problem?id=3335 题目大意:给按照顺时针序的多边形顶点,问其是否有内核. —————————————————————————————— 看了两个小时的资料, ...

  8. POJ 3335 Rotating Scoreboard(多边形的核)

    题目链接 我看的这里:http://www.cnblogs.com/ka200812/archive/2012/01/20/2328316.html 然后整理一下当做模版.0换成eps,会wa,应该要 ...

  9. POJ 3335 Rotating Scoreboard(半平面交求多边形核)

    题目链接 题意 : 给你一个多边形,问你在多边形内部是否存在这样的点,使得这个点能够看到任何在多边形边界上的点. 思路 : 半平面交求多边形内核. 半平面交资料 关于求多边形内核的算法 什么是多边形的 ...

随机推荐

  1. linux查找工具(find,locate,whrers)

    find whereis locate 一.whereis whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s).如果省略参数, ...

  2. 你必须学写 Python 装饰器的五个理由

    你必须学写Python装饰器的五个理由 ----装饰器能对你所写的代码产生极大的正面作用 作者:Aaron Maxwell,2016年5月5日 Python装饰器是很容易使用的.任何一个会写Pytho ...

  3. Java-GC-标记压缩算法

    标记压缩算法 其分为两个阶段标记阶段,和压缩阶段.其中标记阶段和标记清除算法的标记阶段是一样的. 对压缩算法来说,他的工作就是移动所有的可达对象到堆内存的同一区域中,使它们紧凑的排列在一起,从而将所有 ...

  4. JS高级学习历程-11

    [继承] 在php,一个类去继承另一个类,本类实例化出来的对象,既可以调用本身类的成员,也可以调用父类的成员. 在javascript继承主要通过原型实现,构造函数继承一个对象,构造函数的实例会拥有被 ...

  5. JXl常用解析详解

    目的: java解析 excel 无非就是apache poi 或者 jxl 两者在使用上其实都差不多,关键还是看你自己熟悉那个,用那个!我也是初次接触jxl 看很多博客说 jxl只适用于处理小数据量 ...

  6. Jenkins+Gitlab+Ansible自动化部署(一)

    首先准备实验环境 虚拟机 主机名 IP地址 服务 系统版本 内核版本 Vmware Workstation 14 gitlab.example.com 192.168.244.130 gitlab  ...

  7. Kaggle八门神器(一):竞赛神器之XGBoost介绍

    Xgboost为一个十分有效的机器学习模型,在各种竞赛中均可以看到它的身影,同时Xgboost在工业届也有着广泛的应用,本文以Titanic数据集为研究对象,简单地探究Xgboost模型建模过程,同时 ...

  8. 关于Identityserver4和IdentityServer3 授权不兼容的问题

    使用IdentityServer3 作为授权服务器,如果没有设置证书,而且client又没有设置AccessTokenType = AccessTokenType.Reference,则获取token ...

  9. springboot+shiro+cas实现单点登录之shiro端搭建

    github:https://github.com/peterowang/shiro-cas 本文如有配置问题,请查看之前的springboot集成shiro的文章 1.配置ehcache缓存,在re ...

  10. div嵌套时,子元素设置margin-top失效问题

    这是因为父元素的padding设置为0时所产生的bug,它自动将margin-top提升到了父元素上,所以此时我们所设置的margin-top自动就到父元素上了,解决方案: 1.给父元素添加一个pad ...