poj 1474 Video Surveillance 【半平面交】
半平面交求多边形的核,注意边是顺时针给出的
//卡精致死于是换(?)了一种求半平面交的方法……
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=505;
int n,cas;
const double eps=1e-8;
struct dian
{
	double x,y;
	dian(double X=0,double Y=0)
	{
		x=X,y=Y;
	}
	dian operator + (const dian &a) const
	{
		return dian(x+a.x,y+a.y);
	}
	dian operator - (const dian &a) const
	{
		return dian(x-a.x,y-a.y);
	}
	dian operator * (const double &a) const
	{
		return dian(x*a,y*a);
	}
	dian operator / (const double &a) const
	{
		return dian(x/a,y/a);
	}
}a[N],p[N];
struct bian
{
	dian s,v;//s表示向量的起点,v表示向量的方向和长度(从(0,0)射出)
	double a;
	bian(dian S=dian(),dian V=dian())
	{
		s=S,v=V;
		a=atan2(v.y,v.x);
	}
}l[N],s[N];
int sgn(double x)
{
	return x<-eps?-1:x>eps;
}
double cj(dian a,dian b)//叉积
{
	return a.x*b.y-a.y*b.x;
}
double mj(dian a,dian b,dian c)//求有向面积
{
	return cj(b-a,c-a)/2.0;
}
dian jd(bian x,bian y)//求交点
{
	return x.s+x.v*(cj(x.s-y.s,y.v)/cj(y.v,x.v));
}
dian nor(dian a)
{
	return dian(-a.y,a.x);
}
bool px(bian x,bian y)//判断平行
{
	return sgn(cj(y.v,x.v))==0;
}
bool bn(bian x,bian y)//x在y的逆时针方向(平行先左后右
{
	double ar=cj(x.v,y.v);
	return (sgn(ar)>0)||((sgn(ar)==0)&&sgn(cj(x.v,y.s-x.s))>0);
}
bool dn(dian x,bian y)//点在线的逆时针方向
{
	return sgn(cj(y.v,x-y.s))>0;
}
bool cmp(const bian &x,const bian &y)//极角排序
{
	// if(sgn(x.v.y)==0&&sgn(y.v.y)==0)//同与x轴平行
		// return x.v.x<y.v.x;
	// if((sgn(x.v.y)<=0)==(sgn(y.v.y)<=0))//同在x轴上或下(包括x轴)
		// return bn(x,y);
	// return x.v.y<y.v.y;//一上一下下在前
	return sgn(x.a-y.a)==-1;
}
dian ite(bian a,bian b)
{
	return a.s+a.v*(cj(b.v,a.s-b.s)/cj(a.v,b.v));
}
int main()
{
	while(scanf("%d",&n)&&n)
	{
		for(int i=0;i<n;i++)
			scanf("%lf%lf",&p[i].x,&p[i].y);
		p[n]=p[0];
		for(int i=0;i<n;i++)
			l[i]=bian(p[i]-nor(p[i]-p[i+1])*eps,p[i]-p[i+1]);
		sort(l,l+n,cmp);
		int ll=0,rr=0;
		s[rr++]=l[0];
		for(int i=1;i<n;i++)//每次新加入向量,就会删掉在向量右边的交点(线上的也要删),维护的凸包首尾都是要删除的,最后还要模拟插入队头,把队尾中多余的半平面去掉
		{
			while(ll+1<rr&&!dn(p[rr-2],l[i]))
				rr--;
			while(ll+1<rr&&!dn(p[ll],l[i]))
				ll++;
			s[rr++]=l[i];
			if(ll+1<rr&&sgn(cj(s[rr-1].v,s[rr-2].v))==0)
			{
				rr--;
				if(dn(l[i].s,s[rr-1]))
					s[rr-1]=l[i];
			}
			if(ll+1<rr)
				p[rr-2]=ite(s[rr-1],s[rr-2]);
		}
		while(ll+1<rr&&!dn(p[rr-2],s[ll]))
			rr--;//cout<<rr<<endl;
		if(rr-ll>1)
			printf("Floor #%d\nSurveillance is possible.\n",++cas);
		else
			printf("Floor #%d\nSurveillance is impossible.\n",++cas);
		printf("\n");
	}
	return 0;
}
												
											poj 1474 Video Surveillance 【半平面交】的更多相关文章
- POJ 1474 Video Surveillance 半平面交/多边形核是否存在
		
http://poj.org/problem?id=1474 解法同POJ 1279 A一送一 缺点是还是O(n^2) ...nlogn的过几天补上... /********************* ...
 - POJ 1474 Video Surveillance(半平面交)
		
题目链接 2Y,模版抄错了一点. #include <cstdio> #include <cstring> #include <string> #include & ...
 - poj 1474 Video Surveillance - 求多边形有没有核
		
/* poj 1474 Video Surveillance - 求多边形有没有核 */ #include <stdio.h> #include<math.h> const d ...
 - poj 1474 Video Surveillance (半平面交)
		
链接:http://poj.org/problem?id=1474 Video Surveillance Time Limit: 1000MS Memory Limit: 10000K Total ...
 - ●poj 1474 Video Surveillance
		
题链: http://poj.org/problem?id=1474 题解: 计算几何,半平面交 半平面交裸题,快要恶心死我啦... (了无数次之后,一怒之下把onleft改为onright,然后还加 ...
 - POJ1474 Video Surveillance(半平面交)
		
求多边形核的存在性,过了这题但是过不了另一题的,不知道是模板的问题还是什么,但是这个模板还是可以过绝大部分的题的... #pragma warning(disable:4996) #include & ...
 - poj1474Video Surveillance(半平面交)
		
链接 半平面交的模板题,判断有没有核.: 注意一下最后的核可能为一条线,面积也是为0的,但却是有的. #include<iostream> #include <stdio.h> ...
 - 2018.07.03 POJ 1279Art Gallery(半平面交)
		
Art Gallery Time Limit: 1000MS Memory Limit: 10000K Description The art galleries of the new and ver ...
 - POJ 3335 Rotating Scoreboard 半平面交求核
		
LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...
 
随机推荐
- Entity framework自定义字段实现思路
			
ublic class MyModel { public int MyModelID { get; set; } public string FixedProperty1 { get; set; } ...
 - jQuery的一些总结(持续更新中...)
			
本文为原创,转载请注明出处: cnzt 文章:cnzt-p http://www.cnblogs.com/zt-blog/p/6693399.html 1. $.expr[':'] 过滤 ...
 - redis connetced refused remote
			
239down vote I've been stuck with the same issue, and the preceding answer did not help me (albeit w ...
 - [React] Extend styles with styled-components in React
			
In this lesson, you will learn how to extend styles from one styled-component to another in a React ...
 - vue 手风琴组件
			
1.创建组件 SqueezeBox.vue <!-- 手风琴(三级折叠列表) 组件 --> <template> <div class="header" ...
 - 3.将maven项目jar纳入maven仓库,Mave项目依赖另外一个Maven项目的案例
			
 1 若想让maven项目依赖另外一个maven项目.被依赖的项目要在maven仓库中有对应的jar包,所以要对依赖的项目运行mvninstall命令. 2 新建第二个项目模块HelloFrien ...
 - Visual Studio 2017中使用正则修改部分内容  如何使用ILAsm与ILDasm修改.Net exe(dll)文件    C#学习-图解教程(1):格式化数字字符串  小程序开发之图片转Base64(C#、.Net)  jquery遍历table为每一个单元格取值及赋值  。net加密解密相关方法   .net关于坐标之间一些简单操作
			
Visual Studio 2017中使用正则修改部分内容 最近在项目中想实现一个小工具,需要根据类的属性<summary>的内容加上相应的[Description]特性,需要实现的效 ...
 - CMMI 2,3,4,5级涉及的过程域(PA)介绍
			
CMMI中的PA即Process Area的缩写,中文称为过程域.简单的说就是做好一个事情需要的某一个方面,对于软件开发来说,就是做好软件开发需要的某一个方面. CMMI2.3级共有18个过程域( ...
 - Saltstack运行cmd.run重新启动tomcat后出现日志乱码(15)
			
Saltstack使用的cmd.run调用的是核心模块cmdmod.py,以下我们来看一下cmdmod.py模块的源代码: cat /usr/lib/python2.6/site-packages/s ...
 - 【拆分版】Docker-compose构建Zookeeper集群管理Kafka集群
			
写在前边 在搭建Logstash多节点之前,想到就算先搭好Logstash启动会因为日志无法连接到Kafka Brokers而无限重试,所以这里先构建下Zookeeper集群管理的Kafka集群. 众 ...