POJ 3335 (计算几何+半平面交)
来源:互联网 发布:java多用户商城源码 编辑:程序博客网 时间:2024/05/17 02:18
This year, ACM/ICPC World finals will be held in a hall in form of a simple polygon. The coaches and spectators are seated along the edges of the polygon. We want to place a rotating scoreboard somewhere in the hall such that a spectator sitting anywhere on the boundary of the hall can view the scoreboard (i.e., his line of sight is not blocked by a wall). Note that if the line of sight of a spectator is tangent to the polygon boundary (either in a vertex or in an edge), he can still view the scoreboard. You may view spectator's seats as points along the boundary of the simple polygon, and consider the scoreboard as a point as well. Your program is given the corners of the hall (the vertices of the polygon), and must check if there is a location for the scoreboard (a point inside the polygon) such that the scoreboard can be viewed from any point on the edges of the polygon.
The first number in the input line, T is the number of test cases. Each test case is specified on a single line of input in the formn x1 y1 x2 y2 ...xn yn where n (3 ≤ n ≤ 100) is the number of vertices in the polygon, and the pair of integersxi yi sequence specify the vertices of the polygon sorted in order.
The output contains T lines, each corresponding to an input test case in that order. The output line contains either YES or NO depending on whether the scoreboard can be placed inside the hall conforming to the problem conditions.
24 0 0 0 1 1 1 1 08 0 0 0 2 1 2 1 1 2 1 2 2 3 2 3 0
YESNO
题意:简单的判断多边形有木有核
代码:
#include<cstdio>#include<iostream>#include<cstdlib>#include<cstring>#include<algorithm>#include<functional>#include<vector>#include <map>#include<cmath>using namespace std;typedef long long LL;const LL MOD=1e9+7;const double eps=1e-9;const int MAXN=100+23;#define point pair<double,double>#define x first#define y secondvoid getline(double &a,double &b,double &c,point x1,point x2){ a=(x1.y-x2.y); b=(x2.x-x1.x); c=-a*x1.x-b*x1.y;}point intersect(double a,double b,double c,point x1,point x2){ double u = fabs(a * x1.x + b * x1.y + c); double v = fabs(a * x2.x + b * x2.y + c); return point( (x1.x * v + x2.x * u) / (u + v) , (x1.y * v + x2.y * u) / (u + v) );}int n,last,now;point p1[MAXN],p2[MAXN],p3[MAXN];void cut(double a,double b,double c){ now=0; for(int i=1;i<=last;i++) { if(a*p2[i].x+b*p2[i].y+c<=0) { p3[++now]=p2[i]; } else { if(a*p2[i-1].x+b*p2[i-1].y+c<=0) { p3[++now]=intersect(a,b,c,p2[i],p2[i-1]); } if(a*p2[i+1].x+b*p2[i+1].y+c<=0) { p3[++now]=intersect(a,b,c,p2[i],p2[i+1]); } } } //printf("now=%d\n",last); last=now; for(int i=1;i<=last;i++)p2[i]=p3[i]; p2[last+1]=p3[1];p2[0]=p3[last];}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%lf%lf",&p1[i].x,&p1[i].y),p2[i]=p1[i]; p2[n+1]=p1[1];p2[0]=p1[n]; p1[n+1]=p1[1]; last=n; now=0; for(int i=1;i<=n;i++) { double a,b,c; getline(a,b,c,p1[i],p1[i+1]); //printf("%f %f %f\n",a,b,c); cut(a,b,c); } if(last>0)puts("YES"); else puts("NO"); } return 0;}本人蒟蒻,如有错误,还望指正
- POJ 3335 (计算几何+半平面交)
- 【计算几何】半平面交
- 计算几何 || 半平面交
- POJ 1279 Art Gallery (计算几何+半平面交)
- POJ 1755 Triathlon (计算几何+半平面交解决线性规划)
- POJ 3384 Feng Shui (计算几何+半平面交)
- POJ 3335-Rotating Scoreboard(计算几何-半平面交顺时针模板)
- 计算几何_半平面交
- 计算几何学习之半平面交
- 计算几何学习之半平面交
- 计算几何之二分半平面交
- bzoj 2618(计算几何+半平面交)
- POJ 3130 How I Mathematician Wonder What You Are! (计算几何+半平面交)
- poj 3335(半平面交)
- <模板><计算几何>半平面求交学习小记
- 计算几何 || 半平面交 (模板收集)
- 【半平面交】【计算几何】[BZOJ1038][ZJOI2008]瞭望塔
- BSOJ1156:CQOI2006 凸多边形 计算几何--半平面交
- 关于springboot 的一份新手总结
- C++ 深入理解 虚继承、多重继承和直接继承
- CS R14 C(模拟+二维前缀和) ,D(好题,前缀第i位异或+滑动区间),E(树计数+DP(前缀和优化))
- 国科大人工智能技术学院揭牌,第一批研究生正式入学
- 关于博客迁往简书的说明
- POJ 3335 (计算几何+半平面交)
- bash 密码输入
- Delphi学习笔记(一)之语法基础
- jsp页面标签id与onclick内函数重名引发的问题
- MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
- collectionView reloadData 之后 cell消失
- 函数名与函数指针
- adb client远程连接adb server
- iOS开发~SDWebImage是如何做到Url不变的情况下,更新图片内容的