http://poj.org/problem?id=3335

题目大意:给按照顺时针序的多边形顶点,问其是否有内核。

——————————————————————————————

看了两个小时的资料,对板子敲了一个小时,终于将简单的板子题弄过了。

(原本计划去搞风水那道题,但发现我等级的太低了……需要从基础练起半平面交)

代码参考:http://blog.csdn.net/accry/article/details/6070621

理解参考:http://blog.csdn.net/acm_zl/article/details/11153475

(这个理解参考找了很久……我只看得懂这个,先看下面的再看上面的能对理解起到蛮好的帮助)

#include<cstdio>
#include<queue>
#include<cctype>
#include<cstring>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
typedef double dl;
const dl eps=1e-;
const int N=;
struct Point{
dl x;
dl y;
}p[N],point[N],q[N],z;
//point,初始点
//q,暂时存可行点
//p,记录可行点
int n,curcnt,cnt;
//curcnt,暂时存可行点个数
//cnt,记录可行点个数
inline Point getmag(Point a,Point b){
Point s;
s.x=b.x-a.x;s.y=b.y-a.y;
return s;
}
inline dl multiX(Point a,Point b){
return a.x*b.y-b.x*a.y;
}
inline void getline(Point x,Point y,dl &a,dl &b,dl &c){
a=y.y-x.y;
b=x.x-y.x;
c=y.x*x.y-x.x*y.y;
return;
}
inline Point intersect(Point x,Point y,dl a,dl b,dl c){
Point s;
dl u=fabs(a*x.x+b*x.y+c);
dl v=fabs(a*y.x+b*y.y+c);
s.x=(x.x*v+y.x*u)/(u+v);
s.y=(x.y*v+y.y*u)/(u+v);
return s;
}
inline void cut(dl a,dl b,dl c){
curcnt=;
for(int i=;i<=cnt;i++){
if(a*p[i].x+b*p[i].y+c>-eps)q[++curcnt]=p[i];
else{
if(a*p[i-].x+b*p[i-].y+c>eps){
q[++curcnt]=intersect(p[i],p[i-],a,b,c);
}
if(a*p[i+].x+b*p[i+].y+c>eps){
q[++curcnt]=intersect(p[i],p[i+],a,b,c);
}
}
}
for(int i=;i<=curcnt;i++)p[i]=q[i];
p[curcnt+]=p[];p[]=p[curcnt];
cnt=curcnt;
return;
}
inline void init(){
for(int i=;i<=n;i++)p[i]=point[i];
z.x=z.y=;
p[n+]=p[];
p[]=p[n];
point[n+]=point[];
cnt=n;
return;
}
inline void regular(){//调换方向
for(int i=;i<(n+)/;i++)swap(point[i],point[n-i]);
return;
}
inline bool solve(){
//注意:默认点是顺时针,如果题目不是顺时针,规整化方向
init();
for(int i=;i<=n;i++){
dl a,b,c;
getline(point[i],point[i+],a,b,c);
cut(a,b,c);
}
return cnt;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%lf%lf",&point[i].x,&point[i].y);
}
if(!solve())puts("NO");
else puts("YES");
}
return ;
}

POJ3335:Rotating Scoreboard——题解的更多相关文章

  1. poj3335 Rotating Scoreboard

    题目描述: vjudge POJ 题解: 半平面交判核的存在性. 重点在于一个点的核也算核. 这样的话普通的求多边形的版本就要加一个特判. 就是把剩下的一个节点暴力带回所有直线重判,这时判叉积是否$\ ...

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

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

  3. 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)

    Rotating Scoreboard Description This year, ACM/ICPC World finals will be held in a hall in form of a ...

  4. poj 3335 Rotating Scoreboard - 半平面交

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

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

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

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

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

  7. poj 3335 Rotating Scoreboard (Half Plane Intersection)

    3335 -- Rotating Scoreboard 给出一个多边形,要求判断它的内核是否存在. 还是半平面交的题,在这道题中,公告板允许其所在位置与直线共线也算是可见,于是我们就可以将每一条直线微 ...

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

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

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

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

随机推荐

  1. 「日常训练」Girls and Boys(HDU-1068)

    题意 有n个同学,给出同学之间的爱慕关系,选出一个集合使得集合中的人没有爱慕关系.问能选出的最大集合是多少. 分析 二分图的最大独立集. 最大独立集的意思是,在图中选出最多的点,使他们两两之间没有边, ...

  2. caffe Mac 安装

    参考了 https://zhuanlan.zhihu.com/p/24853767 安装caffe的依赖项 brew install --fresh -vd snappy leveldb gflags ...

  3. 了解Python控制流语句——if语句

    控制流 截止到现在,在我们所看过的程序中,总是有一系列语句从上到下精确排列,并交由 Python 忠实地执行.如果你想改变这一工作流程,应该怎么做?就像这样的情况:你需要程序作出一些决定,并依据不同的 ...

  4. Centos7下部署activeMQ消息队列服务

    #1.下载activeMQlinux包 http://activemq.apache.org/activemq-5100-release.html   下载linux的activeMQ包 #2.使用X ...

  5. Matlab提速方法

    1. 向量化. 尽量少用for循环. 2. 循环竖着走比横着走快. 3. 内置函数也有优化的空间 不少内置函数都有大量的error check.直接用profiler找出真正干活的.不少内置函数在网上 ...

  6. 三:Fair Scheduler 公平调度器

    参考资料: http://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/FairScheduler.html http://h ...

  7. Alphabetic Removals(模拟水题)

    You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly ...

  8. ueditor百度编辑器的赋值方法

    示例: http://ueditor.baidu.com/website/onlinedemo.html 引用代码: window.UMEDITOR_HOME_URL = $CONFIG['domai ...

  9. 接口文档管理工具-Postman、Swagger、RAP(转载)

    接口文档管理工具-Postman.Swagger.RAP 转自:http://www.51testing.com/html/10/n-3715910.html 在项目开发测试中,接口文档是贯穿始终的. ...

  10. 2019寒假训练营第三次作业part1-网络空间安全概论第五章

    第五章 网络攻防技术 5.1 网路信息收集技术--网络踩点 黑客入侵系统之前,需要了解目标系统可能存在的: 管理上的安全缺陷和漏洞 网络协议安全缺陷与漏洞 系统安全缺陷与漏洞 黑客实施入侵过程中,需要 ...