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. Manual install on Windows 7 with Apache and MySQL

    These are instructions for installing on Windows 7 desktop (they may also be useful for a server ins ...

  2. K8S全栈容器服务如何助力企业云化创新?

    容器编排管理平台Kubernetes在实践两年多后,市场主导地位被正式确定,随着首批认证服务商的宣布,围绕着容器的应用编排部署服务已然成熟,Kubernetes开始在商业场景为企业创造价值.华为云在K ...

  3. 180713-Spring之借助Redis设计访问计数器之扩展篇

    之前写了一篇博文,简单的介绍了下如何利用Redis配合Spring搭建一个web的访问计数器,之前的内容比较初级,现在考虑对其进行扩展,新增访问者记录 记录当前站点的总访问人数(根据Ip或则设备号) ...

  4. Linux命令应用大词典-第22章 GRUB

    22.1 grub-md5-crypt:使用MD5格式加密口令 22.2 grub-install:在设备上安装GRUB 22.3 grub:进入GRUB命令shell 22.4 grub-crypt ...

  5. lintcode: Missing String

    Missing String  描述: Given two strings, you have to find the missing string. Have you met this questi ...

  6. [SHELL]shell中的数学运算

    一,expr  太麻烦,看的脑壳疼 二,使用方括号 !!!! bash shell用这种方法只支持整数运算,z shell倒是支持浮点型运算 var_1= var_2= var_3= my_var_1 ...

  7. Python数据分析实战-Boston Public Schools GEO数据分析-Part1

    项目目标: Boston Public Schools Geo数据是来自于Boston地区的公共学校的数据,具体描述了学校的坐标,名字,类型等.基于此数据,我们可以学习一些基本的Python数据分析的 ...

  8. Ubuntu16.04安装truffle时的一些错误

    1.使用truffle时出现 Error: /usr/bin/env: node: 没有那个文件或目录 1.如果是用sudo apt-get install nodejs命令安装的nodejs, ub ...

  9. SIG蓝牙mesh笔记3_网络结构

    目录 3. Mesh Networking 3.1 Bearers 承载层 3.2 Network Layer 网络层 3.2.3 Address validity 地址有效性 3.2.4 Netwo ...

  10. JAVA中快速构建BEAN的方法

    首先,创建一个JAVA类,testBean.java. package com.beans; public class testBean { } 然后,添加私有成员字段. package com.be ...