半平面交模板

#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 ansCnt,curCnt,n; double DB(double d){
if(d>eps) return 1;
if(d<-eps) return -1;
return 0;
} void initial(){
for(int i=1;i<=n;i++)
p[i]=pts[i];
p[n+1]=p[1];
p[0]=p[n];
ansCnt=n;
} void getline(point x,point y,double &a,double &b,double &c){
a=y.y-x.y;
b=x.x-y.x;
c=x.y*y.x-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<=ansCnt;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];
}
ansCnt=curCnt;
p[ansCnt+1]=p[1]; p[0]=p[ansCnt];
} 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 cas=0;
while(scanf("%d",&n),n){
cas++;
for(int i=1;i<=n;i++)
scanf("%lf%lf",&pts[i].x,&pts[i].y);
pts[n+1]=pts[1];
slove();
printf("Floor #%d\n",cas);
if(ansCnt>=1)
printf("Surveillance is possible.\n");
else printf("Surveillance is impossible.\n");
printf("\n");
}
return 0;
}

  

POJ 1474的更多相关文章

  1. poj 1474 Video Surveillance - 求多边形有没有核

    /* poj 1474 Video Surveillance - 求多边形有没有核 */ #include <stdio.h> #include<math.h> const d ...

  2. poj 1474 Video Surveillance (半平面交)

    链接:http://poj.org/problem?id=1474 Video Surveillance Time Limit: 1000MS   Memory Limit: 10000K Total ...

  3. ●poj 1474 Video Surveillance

    题链: http://poj.org/problem?id=1474 题解: 计算几何,半平面交 半平面交裸题,快要恶心死我啦... (了无数次之后,一怒之下把onleft改为onright,然后还加 ...

  4. POJ 1474 Video Surveillance 半平面交/多边形核是否存在

    http://poj.org/problem?id=1474 解法同POJ 1279 A一送一 缺点是还是O(n^2) ...nlogn的过几天补上... /********************* ...

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

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

  6. POJ 1474 Video Surveillance(半平面交)

    题目链接 2Y,模版抄错了一点. #include <cstdio> #include <cstring> #include <string> #include & ...

  7. Video Surveillance - POJ 1474(判断是否存在内核)

    题目大意:询问是否在家里装一个监视器就可以监控所有的角落. 分析:赤裸裸的判断多边形内核题目. 代码如下: #include<iostream> #include<string.h& ...

  8. POJ - 1474 :Video Surveillance (半平面交-求核)

    pro:顺时针给定多边形,问是否可以放一个监控,可以监控到所有地方,即问是否存在多边形的核. 此题如果两点在同一边界上(且没有被隔段),也可以相互看到. sol:求多边形是否有核.先给直线按角度排序, ...

  9. poj 1474 Video Surveillance 【半平面交】

    半平面交求多边形的核,注意边是顺时针给出的 //卡精致死于是换(?)了一种求半平面交的方法-- #include<iostream> #include<cstdio> #inc ...

随机推荐

  1. LuoguP3621 [APIO2007]风铃

    https://zybuluo.com/ysner/note/1140124 题面 题面复杂,戳我 解析 看着这道题... 似乎与[HNOI/AHOI2018]道路有不可言妙的相似之处. (题面吓人, ...

  2. KNN in c++

    Pseudo Code of KNN We can implement a KNN model by following the below steps: Load the data Initiali ...

  3. c++ 数据预处理(数据去噪,归一化)

    正态分布3σ原则,把3倍方差之外的点设想为噪声数据来排除. 归一化,将数据经过处理之后限定到一定的范围内,一般都会将数据限定到[0,1]. #include <iostream>#incl ...

  4. IP Address

    http://poj.org/problem?id=2105 #include<stdio.h> #include<string.h> int main() { ]; ] = ...

  5. Your configuration specifies to merge with the ref 'refs/heads/v.autoCheckProduct.20190325' from the remote, but no such ref was fetched.

    问题: 创建新的分支,当我们执行git pull,出现如下错误 解决办法: 1.切换到主分支(或者被依赖的分支,也就是你从哪个分支上拉取新的分支),博主这里是master分支 2.执行以下两个命令 3 ...

  6. 在Winform中怎么实现图片的旋转,比如说实现仪表盘功能,看代码吧,看太不懂的欢迎问

    ; //旋转的角度 //Timer定时器 private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; ...

  7. JavaScript中比较运算符的使用

    比较运算符的基本操作过程是:首先对操作数进行比较,这个操作数可以是数字也可以是字符串,然后返回一个布尔值true或false. 在JavaScript中常用的比较运算符如下表所示. 例如,某商场店庆搞 ...

  8. Leetcode0002--Add Two Numbers 链表求和

    [转载请注明]http://www.cnblogs.com/igoslly/p/8672467.html 来看一下题目: You are given two non-empty linked list ...

  9. 扩展银行项目,添加一个(客户类)Customer类。Customer类将包含一个Account对象。

    练习目标-使用引用类型的成员变量:在本练习中,将扩展银行项目,添加一个(客户类)Customer类.Customer类将包含一个Account对象. 任务 在banking包下的创建Customer类 ...

  10. oracle 命令记录

    监听程序启动停止查看名利: 1.切换到oracle用户:su - oracle 2.查看监听状态:lsnrctl status 3.停止监听:lsnrctl stop 4.启动监听:lsnrctl s ...