题目大意:RT

分析:所谓内核可以理解为在多边形内存在点可以在这个点上看到多边形内部所有的部分,当然怎么求出来就是问题的关键了。我们知道多边形的每条边都是边界值,边的左边和右边肯定是一部分属于多边形一部分属于多边形外,如果这个多边形是顺时针的话那么右边就属于里面,左边就属于外边,如果这条变的外边那么一定是看不到这条边的了,所以可以排出。具体做法如下:

如上图所示:这个多边形按照顺时针来的,有5个顶点,分别是12345,首先我们先把边12拿出,发现,123都属于边12的右边,45不属于,所以可以吧45扔掉,但是我们发现12和34相交与点A,所以当发现有点在左边的时候需要判断一下它所连接的线是否和这条线有交点,如果有把交点保存下来,可以使用叉积判断左右边。

代码如下:


  1. #include<iostream>
  2. #include<string.h>
  3. #include<stdio.h>
  4. #include<algorithm>
  5. #include<math.h>
  6. #include<queue>
  7. using namespace std;
  8.  
  9. const int MAXN = ;
  10. const int oo = 1e9+;
  11. const double EPS = 1e-;
  12.  
  13. int Sign(double t)
  14. {
  15. if(t > EPS)
  16. return ;
  17. if(fabs(t) < EPS)
  18. return ;
  19. return -;
  20. }
  21.  
  22. struct Point
  23. {
  24. double x, y;
  25. Point(double x=, double y=):x(x),y(y){}
  26. Point operator - (const Point &t)const{
  27. return Point(x-t.x, y-t.y);
  28. }
  29. double operator ^(const Point &t)const{
  30. return x*t.y - y*t.x;
  31. }
  32.  
  33. }p[MAXN], in[MAXN];
  34. struct Segment
  35. {///ax + by = c
  36. Point S, E;
  37. double a, b, c;
  38. Segment(Point S=, Point E=):S(S), E(E){
  39. a = S.y - E.y;
  40. b = E.x - S.x;
  41. c = E.x*S.y - S.x*E.y;
  42. }
  43. Point crossNode(const Segment &t)const{
  44. Point res;
  45.  
  46. res.x = (c*t.b-t.c*b) / (a*t.b-t.a*b);
  47. res.y = (c*t.a-t.c*a) / (b*t.a-t.b*a);
  48.  
  49. return res;
  50. }
  51. int Mul(const Point &t)
  52. {///用叉积判断方向
  53. return Sign((E-S)^(t-S));
  54. }
  55. };
  56. int CutPoly(Segment L, int N)
  57. {
  58. Point tmp[MAXN];
  59. int cnt = ;
  60.  
  61. for(int i=; i<=N; i++)
  62. {
  63. if(L.Mul(in[i]) <= )
  64. tmp[++cnt] = in[i];
  65. else
  66. {
  67. if(L.Mul(in[i-]) < )///求出交点
  68. tmp[++cnt] = L.crossNode(Segment(in[i-],in[i]));
  69. if(L.Mul(in[i+]) < )
  70. tmp[++cnt] = L.crossNode(Segment(in[i],in[i+]));
  71. }
  72. }
  73.  
  74. for(int i=; i<=cnt; i++)
  75. in[i] = tmp[i];
  76. in[] = in[cnt], in[cnt+] = in[];
  77.  
  78. return cnt;
  79. }
  80.  
  81. int main()
  82. {
  83. int N;
  84.  
  85. while(scanf("%d", &N) != EOF && N)
  86. {
  87. int M;
  88.  
  89. for(int i=; i<=N; i++)
  90. {
  91. scanf("%lf%lf", &p[i].x, &p[i].y);
  92. in[i] = p[i];
  93. }
  94. in[] = p[] = p[N];
  95. in[N+] = p[N+] = p[];
  96. M = N;
  97.  
  98. for(int i=; i<=N; i++)
  99. M = CutPoly(Segment(p[i],p[i+]), M);
  100.  
  101. if(M > )
  102. printf("YES\n");
  103. else
  104. printf("NO\n");
  105. }
  106.  
  107. return ;
  108. }

Rotating Scoreboard - POJ 3335(半面相交求多边形内核)的更多相关文章

  1. poj3335 半交平面,多边形内核

    Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5300   Accepted: 21 ...

  2. [poj] 3907 Build Your Home || 求多边形面积

    原题 多组数据,到0为止. 每次给出按顺序的n个点(可能逆时针,可能顺时针),求多边形面积(保留整数) 多边形面积为依次每条边(向量)叉积/2的和 \(S=\sum _{i=1}^{n-1}p[i]* ...

  3. [poj 1039]Pipes[线段相交求交点]

    题意: 无反射不透明管子, 问从入口射入的所有光线最远能到达的横坐标. 贯穿也可. 思路: 枚举每一组经过 up [ i ] 和 down [ j ] 的直线, 计算最远点. 因为无法按照光线生成的方 ...

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

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

  5. poj 3335 Rotating Scoreboard - 半平面交

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

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

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

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

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

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

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

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

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

随机推荐

  1. javascript 返回顶部

    <style> #linGoTopBtn {    POSITION: fixed; TEXT-ALIGN: center; LINE-HEIGHT: 30px; WIDTH: 30px; ...

  2. sass中 混合宏 VS 继承 VS 占位符 各自的使用时机和特点

    初学者都常常纠结于这个问题“什么时候用混合宏,什么时候用继承,什么时候使用占位符?”其实他们各有各的优点与缺点,先来看看他们使用效果: a) Sass 中的混合宏使用 举例代码见 2-24 行 编译出 ...

  3. LeetCode【第一题】Two Sum

    准备刷一刷LeetCode了. 题目: ''' Given an array of integers, return indices of the two numbers such that they ...

  4. bzoj 2693: jzptab 线性筛积性函数

    2693: jzptab Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 444  Solved: 174[Submit][Status][Discus ...

  5. [BZOJ 3530] [Sdoi2014] 数数 【AC自动机+DP】

    题目链接:BZOJ - 3530 题目分析 明显是 AC自动机+DP,外加数位统计. WZY 神犇出的良心省选题,然而去年我太弱..比现在还要弱得多.. 其实现在做这道题,我自己也没想出完整解法.. ...

  6. 纯手工全删除域内最后一个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/ 没办法, ...

  7. CollapsingToolbarLayout

    CollapsingToolbarLayout作用是提供了一个可以折叠的Toolbar,它继承至FrameLayout,给它设置layout_scrollFlags,它可以控制包含在Collapsin ...

  8. Markdown各种小问题汇总

    如何分割Quote? How can I write two separate blockquotes in sequence using markdown? > Imagination is ...

  9. 水平/竖直居中在旧版Safari上的bug

    今天调了两个出现在旧版Safari上的layout bug. 它们最初是在同事的iPad上被发现的, 我在自己桌面上安装的Safari 5.1.7上也能够复现. Bug1: .vertical-cen ...

  10. INFORMATION_SCHEMA.INNODB_LOCKS

    INNODB_LOCKS Table: INNODB_LOCKS 表 包含信息关于每个锁 一个InnoDB 事务已经请求 但是没有获得锁, 每个lock 一个事务持有是堵塞另外一个事务 centos6 ...