3335 -- Rotating Scoreboard

  给出一个多边形,要求判断它的内核是否存在。

  还是半平面交的题,在这道题中,公告板允许其所在位置与直线共线也算是可见,于是我们就可以将每一条直线微小的移动,然后判断是够能够交出多边形,这样做是因为对于半平面交是不能直接判断是够交集是一个点的情况的。

代码如下:

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath> using namespace std; struct Point {
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
} ;
template<class T> T sqr(T x) { return x * x;}
typedef Point Vec;
Vec operator + (Vec a, Vec b) { return Vec(a.x + b.x, a.y + b.y);}
Vec operator - (Vec a, Vec b) { return Vec(a.x - b.x, a.y - b.y);}
Vec operator * (Vec a, double p) { return Vec(a.x * p, a.y * p);}
Vec operator / (Vec a, double p) { return Vec(a.x / p, a.y / p);} const double EPS = 1e-;
const double PI = acos(-1.0);
inline int sgn(double x) { return (x > EPS) - (x < -EPS);} inline double dotDet(Vec a, Vec b) { return a.x * b.x + a.y * b.y;}
inline double crossDet(Vec a, Vec b) { return a.x * b.y - a.y * b.x;}
inline double dotDet(Point o, Point a, Point b) { return dotDet(a - o, b - o);}
inline double crossDet(Point o, Point a, Point b) { return crossDet(a - o, b - o);}
inline double vecLen(Vec x) { return sqrt(dotDet(x, x));}
inline double toRad(double deg) { return deg / 180.0 * PI;}
inline double angle(Vec v) { return atan2(v.y, v.x);}
inline Vec vecUnit(Vec x) { return x / vecLen(x);}
inline Vec normal(Vec x) { return Vec(-x.y, x.x) / vecLen(x);} const int N = ;
struct DLine {
Point p;
Vec v;
double ang;
DLine() {}
DLine(Point p, Vec v) : p(p), v(v) { ang = atan2(v.y, v.x);}
bool operator < (DLine L) const { return ang < L.ang;}
DLine move(double x) {
Vec nor = normal(v);
nor = nor * x;
return DLine(p + nor, v);
}
} dl[N];
Point pt[N]; inline bool onLeft(DLine L, Point p) { return crossDet(L.v, p - L.p) > ;}
Point dLineIntersect(DLine a, DLine b) {
Vec u = a.p - b.p;
double t = crossDet(b.v, u) / crossDet(a.v, b.v);
return a.p + a.v * t;
} struct Poly {
vector<Point> pt;
Poly() { pt.clear();}
~Poly() {}
Poly(vector<Point> &pt) : pt(pt) {}
Point operator [] (int x) { return pt[x];}
int size() { return pt.size();}
double area() {
double ret = 0.0;
int sz = pt.size();
pt.push_back(pt[]);
for (int i = ; i <= sz; i++) ret += crossDet(pt[i], pt[i - ]);
pt.pop_back();
return fabs(ret / 2.0);
}
} ; Poly halfPlane(DLine *L, int n) {
Poly ret = Poly();
sort(L, L + n);
int fi, la;
Point *p = new Point[n];
DLine *q = new DLine[n];
q[fi = la = ] = L[];
for (int i = ; i < n; i++) {
while (fi < la && !onLeft(L[i], p[la - ])) la--;
while (fi < la && !onLeft(L[i], p[fi])) fi++;
q[++la] = L[i];
if (sgn(crossDet(q[la].v, q[la - ].v)) == ) {
la--;
if (onLeft(q[la], L[i].p)) q[la] = L[i];
}
if (fi < la) p[la - ] = dLineIntersect(q[la - ], q[la]);
}
while (fi < la && !onLeft(q[fi], p[la - ])) la--;
if (la <= fi) return ret;
p[la] = dLineIntersect(q[la], q[fi]);
for (int i = fi; i <= la; i++) ret.pt.push_back(p[i]);
return ret;
} bool isClockwise(Point *pt, int n) {
double sum = 0.0;
pt[n] = pt[];
Point O = Point(0.0, 0.0);
for (int i = ; i < n; i++) {
sum += crossDet(O, pt[i], pt[i + ]);
}
return sum < ;
} int main() {
// freopen("in", "r", stdin);
int T, n;
cin >> T;
while (T-- && cin >> n) {
for (int i = ; i < n; i++) cin >> pt[i].x >> pt[i].y;
pt[n] = pt[];
if (isClockwise(pt, n)) for (int i = ; i < n; i++) dl[i] = DLine(pt[i + ], pt[i] - pt[i + ]).move(-EPS);
else for (int i = ; i < n; i++) dl[i] = DLine(pt[i], pt[i + ] - pt[i]).move(-EPS);
Poly tmp = halfPlane(dl, n);
if (tmp.size() > ) puts("YES");
else puts("NO");
}
return ;
} /*
3
6
0 0
100 0
100 100
0 100
50 75
50 25
4
0 0
0 1
1 1
1 0
8
0 0
0 2
1 2
1 1
2 1
2 2
3 2
3 0
*/

——written by Lyon

poj 3335 Rotating Scoreboard (Half Plane Intersection)的更多相关文章

  1. poj 3335 Rotating Scoreboard - 半平面交

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

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

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

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

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

  4. POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交

    题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...

  5. POJ 3335 Rotating Scoreboard 半平面交求核

    LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...

  6. poj 3335 Rotating Scoreboard

    http://poj.org/problem?id=3335 #include <cstdio> #include <cstring> #include <algorit ...

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

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

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

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

  9. poj 1279 Art Gallery (Half Plane Intersection)

    1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...

随机推荐

  1. Js Array 删除

    数组删除操作 Array.prototype.inArray = function (e) {for (i = 0; i < this.length; i++) {if (this[i] == ...

  2. .NET EasyUI datebox添加清空功能

    前言,前段时间的项目使用EasyUI框架搭建,使用了其自带的一系列组件.但对于datebox,其功能别的不多说,令人蛋疼的是它居然没有清空功能,这让在搜索区域中摆了日期条件的咋整啊,没办法,既然用了这 ...

  3. 从0开始学习 GitHub 系列之「06.团队合作利器 Branch」

    Git 相比于 SVN 最强大的一个地方就在于「分支」,Git 的分支操作简直不要太方便,而实际项目开发中团队合作最依赖的莫过于分支了,关于分支前面的系列也提到过,但是本篇会详细讲述什么是分支.分支的 ...

  4. 苹果审核不通过,程序/游戏不兼容IPV6网络

    最近苹果升级的IOS10,所以那边网络环境变成IPV6,如果你的程序不兼容IPV6,苹果的程序会以这个不兼容的原因驳回审核. 那么如何让自己的程序兼容这个?方法其实C#本来已经提供给你的,而且很简单, ...

  5. Quarz框架学习

    参考博客:https://www.cnblogs.com/zhanghaoliang/p/7886110.html

  6. FastAdmin 使用 phpmail 出现 spl_autoload_register 错误

    FastAdmin 使用 phpmail 出现 spl_autoload_register 错误 现象 意思是 __autoload() 已经废弃 问题来源于:https://ask.fastadmi ...

  7. 会话技术之cookie(记录当前时间、浏览记录的记录和清除)

    cookie 会话技术: 当用户打开浏览器的时候,访问不同的资源,直到用户将浏览器关闭,可以认为这是一次会话. 作用: 因为http协议是一个无状态的协议,它不会记录上一次访问的内容.用户在访问过程中 ...

  8. em grid control网格控制

    网格控制 必须管理许多的数据库.应用服务器.web服务器和其他构件的企业可以采用em grid control Em grid control是一个基于web的用户界面,它与oracle企业内所有构件 ...

  9. ThinkPHP中_after_update、_before_update等的用法

    https://blog.csdn.net/aslackers/article/details/50339163 TP系统\Think\Model类里隐藏了几个有用的方法: _before_inser ...

  10. 重温Observer模式--热水器·改

    引言 在 C#中的委托和事件 一文的后半部分,讲述了Observer(观察者)模式,并使用委托和事件实现了这个模式.实际上,不使用委托和事件,一样可以实现Observer模式.在本文中,我将使用GOF ...