poj3335 Rotating Scoreboard
题目描述:
题解:
半平面交判核的存在性。
重点在于一个点的核也算核。
这样的话普通的求多边形的版本就要加一个特判。
就是把剩下的一个节点暴力带回所有直线重判,这时判叉积是否$\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的更多相关文章
- 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard
山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...
- 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)
Rotating Scoreboard Description This year, ACM/ICPC World finals will be held in a hall in form of a ...
- poj 3335 Rotating Scoreboard - 半平面交
/* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...
- poj 3335 Rotating Scoreboard(半平面交)
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6420 Accepted: 25 ...
- POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...
- poj 3335 Rotating Scoreboard (Half Plane Intersection)
3335 -- Rotating Scoreboard 给出一个多边形,要求判断它的内核是否存在. 还是半平面交的题,在这道题中,公告板允许其所在位置与直线共线也算是可见,于是我们就可以将每一条直线微 ...
- POJ3335:Rotating Scoreboard——题解
http://poj.org/problem?id=3335 题目大意:给按照顺时针序的多边形顶点,问其是否有内核. —————————————————————————————— 看了两个小时的资料, ...
- POJ 3335 Rotating Scoreboard(多边形的核)
题目链接 我看的这里:http://www.cnblogs.com/ka200812/archive/2012/01/20/2328316.html 然后整理一下当做模版.0换成eps,会wa,应该要 ...
- POJ 3335 Rotating Scoreboard(半平面交求多边形核)
题目链接 题意 : 给你一个多边形,问你在多边形内部是否存在这样的点,使得这个点能够看到任何在多边形边界上的点. 思路 : 半平面交求多边形内核. 半平面交资料 关于求多边形内核的算法 什么是多边形的 ...
随机推荐
- 外网连接Mysql云数据库
购买好Mysql云数据库,这里是腾讯云 在管理中把外网地址开通,然后可以看到本云数据库的外网地址 注意:外网地址com到前面才是连接地址,冒号后面的10057是连接的端口号,可以看下面的连接语句 cm ...
- PJzhang:kali linux安装金山wps、永中office、sougoupinyin、ibuspiyin
猫宁!!! 参考链接:https://www.cnblogs.com/liuxingbusi/p/9277127.html https://www.cnblogs.com/xcb0730/p/6808 ...
- 使用tcpdump抓取EOS帐户创建与交易数据
基本环境配置 EOS 版本:1.0.1(2018-06-04更新) 节点nodeos http监听端口:127.0.0.1:8888 本地钱包keosd http监听端口:127.0.0.1:89 ...
- 条件分页 分页条件和页参数传递方式一 超链接拼串 方式二 使用查询表单searchForm
<%-- Created by IntelliJ IDEA. User: jie Date: 2019/5/10 Time: 20:00 To change this template use ...
- Java获取路径
"./" 代表当前目录,"../"代表上级目录 后续更新!!!
- Hexo - 记录一次Pages服务部署失败的原因
问题与分析 某天忽然发现,一直运行得好好的Pages服务部署失败了,GitHub Pages报错如下: Your site is having problems building: The tag c ...
- Python面向对象之鸭子类型
python没有多态?他有什么? 他有鸭子类型. 鸭子类型 : 看着像鸭子,他就是鸭子. 比如一些类,他们中有一些方法,有着相同的功能, 这时为我们将这些相同功能的名字命名为一样的. 那么这些类 都互 ...
- 删除vi编辑产生的.swp文件(linux编辑文件没有退出时直接关闭程序产生的临时文件)
关于swp文件 使用vi,经常可以看到swp这个文件,那这个文件是怎么产生的呢,当你打开一个文件,vi就会生成这么一个.(filename)swp文件以备不测(不测下面讨论),如果你正常退出,那么这个 ...
- Mysql修改server uuid
在主从复制的时候如果第二个虚拟机是复制过去的,需要修改 https://blog.csdn.net/pratise/article/details/80413198 1. 首先要查找到mysql的安装 ...
- C#中的XML文档注释-推荐的文档注释标记
文档注释是为了方便自己和他人更好地理解代码所实现的功能.下面记录了一些常用的文档注释标记: <C> 用法: <c>text</c> 将说明中的文本标记为代码.例如: ...