Rotating Scoreboard - POJ 3335(半面相交求多边形内核)
题目大意:RT
分析:所谓内核可以理解为在多边形内存在点可以在这个点上看到多边形内部所有的部分,当然怎么求出来就是问题的关键了。我们知道多边形的每条边都是边界值,边的左边和右边肯定是一部分属于多边形一部分属于多边形外,如果这个多边形是顺时针的话那么右边就属于里面,左边就属于外边,如果这条变的外边那么一定是看不到这条边的了,所以可以排出。具体做法如下:
如上图所示:这个多边形按照顺时针来的,有5个顶点,分别是12345,首先我们先把边12拿出,发现,123都属于边12的右边,45不属于,所以可以吧45扔掉,但是我们发现12和34相交与点A,所以当发现有点在左边的时候需要判断一下它所连接的线是否和这条线有交点,如果有把交点保存下来,可以使用叉积判断左右边。
代码如下:
- #include<iostream>
- #include<string.h>
- #include<stdio.h>
- #include<algorithm>
- #include<math.h>
- #include<queue>
- using namespace std;
- const int MAXN = ;
- const int oo = 1e9+;
- const double EPS = 1e-;
- int Sign(double t)
- {
- if(t > EPS)
- return ;
- if(fabs(t) < EPS)
- return ;
- return -;
- }
- struct Point
- {
- double x, y;
- Point(double x=, double y=):x(x),y(y){}
- Point operator - (const Point &t)const{
- return Point(x-t.x, y-t.y);
- }
- double operator ^(const Point &t)const{
- return x*t.y - y*t.x;
- }
- }p[MAXN], in[MAXN];
- struct Segment
- {///ax + by = c
- Point S, E;
- double a, b, c;
- Segment(Point S=, Point E=):S(S), E(E){
- a = S.y - E.y;
- b = E.x - S.x;
- c = E.x*S.y - S.x*E.y;
- }
- Point crossNode(const Segment &t)const{
- Point res;
- res.x = (c*t.b-t.c*b) / (a*t.b-t.a*b);
- res.y = (c*t.a-t.c*a) / (b*t.a-t.b*a);
- return res;
- }
- int Mul(const Point &t)
- {///用叉积判断方向
- return Sign((E-S)^(t-S));
- }
- };
- int CutPoly(Segment L, int N)
- {
- Point tmp[MAXN];
- int cnt = ;
- for(int i=; i<=N; i++)
- {
- if(L.Mul(in[i]) <= )
- tmp[++cnt] = in[i];
- else
- {
- if(L.Mul(in[i-]) < )///求出交点
- tmp[++cnt] = L.crossNode(Segment(in[i-],in[i]));
- if(L.Mul(in[i+]) < )
- tmp[++cnt] = L.crossNode(Segment(in[i],in[i+]));
- }
- }
- for(int i=; i<=cnt; i++)
- in[i] = tmp[i];
- in[] = in[cnt], in[cnt+] = in[];
- return cnt;
- }
- int main()
- {
- int N;
- while(scanf("%d", &N) != EOF && N)
- {
- int M;
- for(int i=; i<=N; i++)
- {
- scanf("%lf%lf", &p[i].x, &p[i].y);
- in[i] = p[i];
- }
- in[] = p[] = p[N];
- in[N+] = p[N+] = p[];
- M = N;
- for(int i=; i<=N; i++)
- M = CutPoly(Segment(p[i],p[i+]), M);
- if(M > )
- printf("YES\n");
- else
- printf("NO\n");
- }
- return ;
- }
Rotating Scoreboard - POJ 3335(半面相交求多边形内核)的更多相关文章
- poj3335 半交平面,多边形内核
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5300 Accepted: 21 ...
- [poj] 3907 Build Your Home || 求多边形面积
原题 多组数据,到0为止. 每次给出按顺序的n个点(可能逆时针,可能顺时针),求多边形面积(保留整数) 多边形面积为依次每条边(向量)叉积/2的和 \(S=\sum _{i=1}^{n-1}p[i]* ...
- [poj 1039]Pipes[线段相交求交点]
题意: 无反射不透明管子, 问从入口射入的所有光线最远能到达的横坐标. 贯穿也可. 思路: 枚举每一组经过 up [ i ] 和 down [ j ] 的直线, 计算最远点. 因为无法按照光线生成的方 ...
- POJ 3335 Rotating Scoreboard(半平面交求多边形核)
题目链接 题意 : 给你一个多边形,问你在多边形内部是否存在这样的点,使得这个点能够看到任何在多边形边界上的点. 思路 : 半平面交求多边形内核. 半平面交资料 关于求多边形内核的算法 什么是多边形的 ...
- poj 3335 Rotating Scoreboard - 半平面交
/* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
- POJ 3335 Rotating Scoreboard 半平面交求核
LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...
- 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(半平面交)
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6420 Accepted: 25 ...
随机推荐
- javascript 返回顶部
<style> #linGoTopBtn { POSITION: fixed; TEXT-ALIGN: center; LINE-HEIGHT: 30px; WIDTH: 30px; ...
- sass中 混合宏 VS 继承 VS 占位符 各自的使用时机和特点
初学者都常常纠结于这个问题“什么时候用混合宏,什么时候用继承,什么时候使用占位符?”其实他们各有各的优点与缺点,先来看看他们使用效果: a) Sass 中的混合宏使用 举例代码见 2-24 行 编译出 ...
- LeetCode【第一题】Two Sum
准备刷一刷LeetCode了. 题目: ''' Given an array of integers, return indices of the two numbers such that they ...
- bzoj 2693: jzptab 线性筛积性函数
2693: jzptab Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 444 Solved: 174[Submit][Status][Discus ...
- [BZOJ 3530] [Sdoi2014] 数数 【AC自动机+DP】
题目链接:BZOJ - 3530 题目分析 明显是 AC自动机+DP,外加数位统计. WZY 神犇出的良心省选题,然而去年我太弱..比现在还要弱得多.. 其实现在做这道题,我自己也没想出完整解法.. ...
- 纯手工全删除域内最后一个EXCHANGE--How to Manually Uninstall Last Exchange 2010 Server from Organization
http://www.itbigbang.com/how-to-manually-uninstall-last-exchange-2010-server-from-organization/ 没办法, ...
- CollapsingToolbarLayout
CollapsingToolbarLayout作用是提供了一个可以折叠的Toolbar,它继承至FrameLayout,给它设置layout_scrollFlags,它可以控制包含在Collapsin ...
- Markdown各种小问题汇总
如何分割Quote? How can I write two separate blockquotes in sequence using markdown? > Imagination is ...
- 水平/竖直居中在旧版Safari上的bug
今天调了两个出现在旧版Safari上的layout bug. 它们最初是在同事的iPad上被发现的, 我在自己桌面上安装的Safari 5.1.7上也能够复现. Bug1: .vertical-cen ...
- INFORMATION_SCHEMA.INNODB_LOCKS
INNODB_LOCKS Table: INNODB_LOCKS 表 包含信息关于每个锁 一个InnoDB 事务已经请求 但是没有获得锁, 每个lock 一个事务持有是堵塞另外一个事务 centos6 ...