/*半平面交求核心的增量法:
假设前N-1个半平面交,对于第N个半平面,只需用它来交前N-1个平面交出的多边形。
算法开始时,调整点的方向为顺时针方向,对于是否为顺时针,只需求出其面积,若为正,必为逆时针的。
对于每相邻两点求出一条直线,用该直线去交其半平面,并求出交点及判断原多边形点的方位。
*/ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN=110;
const double eps=1e-8; struct point {
double x,y;
};
point pts[MAXN],p[MAXN],q[MAXN];
int n,cCnt,curCnt; int DB(double d){
if(d>eps) return 1;
if(d<-eps) return -1;
return 0;
} double getArea(point *tmp, int n){
double ans=0;
for(int i=1;i<=n;i++)
ans+=(tmp[i].x*tmp[i+1].y-tmp[i].y*tmp[i+1].x);
return ans/2;
} void Adjust(point *ps,int n){
for(int i = 1; i < (n+1)/2; i ++)
swap(ps[i], ps[n-i]);
} void initial(){
double area=getArea(pts,n);
if(DB(area)==1) Adjust(pts,n);
for(int i=1;i<=n;i++)
p[i]=pts[i];
p[n+1]=p[1];
p[0]=p[n];
cCnt=n;
} void getline(point x,point y,double &a,double &b,double &c){
a = y.y - x.y;
b = x.x - y.x;
c = y.x * x.y - x.x * y.y;
} point intersect(point x,point y,double a,double b,double c){
double u = fabs(a * x.x + b * x.y + c);
double v = fabs(a * y.x + b * y.y + c);
point pt;
pt.x=(x.x * v + y.x * u) / (u + v);
pt.y=(x.y * v + y.y * u) / (u + v);
return pt;
} void cut(double a,double b,double c){
curCnt=0;
for(int i=1;i<=cCnt;i++){
if(DB(a*p[i].x+b*p[i].y+c)>=0) q[++curCnt] = p[i];
else {
if(DB(a*p[i-1].x + b*p[i-1].y + c )>0){
q[++curCnt] = intersect(p[i],p[i-1],a,b,c);
}
if(DB(a*p[i+1].x + b*p[i+1].y + c )> 0){
q[++curCnt] = intersect(p[i],p[i+1],a,b,c);
}
}
}
for(int i = 1; i <= curCnt; ++i)p[i] = q[i];
p[curCnt+1] = q[1];p[0] = p[curCnt];
cCnt = curCnt;
} void slove(){
initial();
for(int i=1;i<=n;i++){
double a,b,c;
getline(pts[i],pts[i+1],a,b,c);
cut(a,b,c);
}
} int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lf%lf",&pts[i].x,&pts[i].y);
pts[n+1]=pts[1];
slove();
if(cCnt>=1) printf("YES\n");
else printf("NO\n");
}
return 0;
}

  

POJ 3335的更多相关文章

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

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

  2. poj 3335 Rotating Scoreboard - 半平面交

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

  3. poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积

    /*************** poj 3335 点序顺时针 ***************/ #include <iostream> #include <cmath> #i ...

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

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

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

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

  6. 三道半平面交测模板题 Poj1474 Poj 3335 Poj 3130

    求半平面交的算法是zzy大神的排序增量法. ///Poj 1474 #include <cmath> #include <algorithm> #include <cst ...

  7. poj 3335(半平面交)

    链接:http://poj.org/problem?id=3335     //大牛们常说的测模板题 ------------------------------------------------- ...

  8. poj 3335 Rotating Scoreboard

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

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

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

  10. 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard

    山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...

随机推荐

  1. 杂项:Web API

    ylbtech-杂项:Web API 今天的web计算平台包含了广泛的功能,其中的大部分均可以通过API(应用程序编程接口)访问. 从简单的社会书签服务del.icio.us,到复杂得多的amazon ...

  2. vue.js的第一个程序

    Vue.js是一个轻巧.高性能.可组件化的MVVM库,同时拥有非常容易上手的API. 1.安装 下载 git clone https://github.com/vuejs/vue.git 页面中直接引 ...

  3. 模拟Queue(wait/notify)

    BlockingQueue:顾名思义,首先它是一个队列,并且支持阻塞的机制,阻塞的放入和得到数据.我们要实现LinkedBlockingQueue下面的两个方法put和take. put(anObje ...

  4. [BZOJ1307][ZJOI2008]生日聚会PARTY

    ...一开始用了三维的...甚至尝试把它搞成二维的...后来发现根本没法转移呀... 既然dalao说这是初中题,那它就算是一道初中题吧... dp[i][j][k][p]表示当前有i个男生j个女生, ...

  5. struts2结果处理、获取参数(二)

    结果处理 1.转发 type可以不写,默认就是转发 <package name="hello" namespace="/hello" extends=&q ...

  6. CABasicAnimation - 上下滑动动画

    #import <UIKit/UIKit.h> @interface TJProgressView : UIView @property(nonatomic,assign)CGFloat ...

  7. 关于SSL证书配置、升级的一些问题总结

    SSL会成为网站.APP.小程序(小程序已经强制使用https)等项目的标配.关于SSL证书安装使用的问题今天总结下,以备用. 环境配置:windows server 2008 R2和IIS7.0 1 ...

  8. Centos6.6 编译安装nginx

    一.基本环境 nginx 1.9版以后增加了一些新的特性,支持tcp负载均衡,不过这次还是用1.8.0,这里面有个memcached的代理模块,有时间再测试下 1.centos6.6 2.nginx1 ...

  9. html 复杂表格

    123456789 123456789 0000000000 日期 123456789 1234560000000789 ----------- ----------- ----------- --- ...

  10. react新版本生命周期

    给componentWillMount componentWillReceiveProps componentWillUpdate生命周期加上UNSAFE_前缀,表明其不安全性,并将在未来版本将其移除 ...