Video Surveillance - POJ 1474(判断是否存在内核)
题目大意:询问是否在家里装一个监视器就可以监控所有的角落。
分析:赤裸裸的判断多边形内核题目。
代码如下:
- #include<iostream>
- #include<string.h>
- #include<stdio.h>
- #include<algorithm>
- #include<math.h>
- #include<queue>
- using namespace std;
- const int MAXN = ;
- const int oo = 1e9+;
- const double EPS = 1e-;
- int Sign(double t)
- {
- if(t > EPS)
- return ;
- if(fabs(t) < EPS)
- return ;
- return -;
- }
- struct Point
- {
- double x, y;
- Point(double x=, double y=):x(x),y(y){}
- Point operator - (const Point &t)const{
- return Point(x-t.x, y-t.y);
- }
- double operator ^(const Point &t)const{
- return x*t.y - y*t.x;
- }
- }p[MAXN], in[MAXN];
- struct Segment
- {
- Point S, E;
- double a, b, c;
- Segment(Point S=, Point E=):S(S), E(E){
- a = S.y - E.y;
- b = E.x - S.x;
- c = E.x*S.y - S.x*E.y;
- }
- Point crossNode(const Segment &t)const{
- Point res;
- res.x = (c*t.b-t.c*b) / (a*t.b-t.a*b);
- res.y = (c*t.a-t.c*a) / (b*t.a-t.b*a);
- return res;
- }
- int Mul(const Point &t)
- {///用叉积判断方向
- return Sign((E-S)^(t-S));
- }
- };
- int CutPoly(Segment L, int N)
- {
- Point tmp[MAXN];
- int cnt = ;
- for(int i=; i<=N; i++)
- {
- if(L.Mul(in[i]) <= )
- tmp[++cnt] = in[i];
- else
- {
- if(L.Mul(in[i-]) < )///求出交点
- tmp[++cnt] = L.crossNode(Segment(in[i-],in[i]));
- if(L.Mul(in[i+]) < )
- tmp[++cnt] = L.crossNode(Segment(in[i],in[i+]));
- }
- }
- for(int i=; i<=cnt; i++)
- in[i] = tmp[i];
- in[] = in[cnt], in[cnt+] = in[];
- return cnt;
- }
- int main()
- {
- int N, t=;
- while(scanf("%d", &N) != EOF && N)
- {
- int M;
- double s=;
- for(int i=; i<=N; i++)
- {
- scanf("%lf%lf", &p[i].x, &p[i].y);
- in[i] = p[i];
- if(i != )
- s += p[i].x*p[i-].y - p[i].y*p[i-].x;
- }
- s += p[].x*p[N].y - p[].y*p[N].x;
- if(s < )
- {
- for(int i=; i<=N/; i++)
- {
- swap(p[i], p[N-i+]);
- swap(in[i], in[N-i+]);
- }
- }
- in[] = p[] = p[N];
- in[N+] = p[N+] = p[];
- M = N;
- for(int i=; i<=N; i++)
- M = CutPoly(Segment(p[i],p[i+]), M);
- printf("Floor #%d\n", t++);
- if(M > )
- printf("Surveillance is possible.\n\n");
- else
- printf("Surveillance is impossible.\n\n");
- }
- return ;
- }
Video Surveillance - POJ 1474(判断是否存在内核)的更多相关文章
- 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 ...
- JavaScript,一个超级简单的方法判断浏览器的内核前缀
先说明,此处的方法是说超级简单的方法,不是指代码超级少,而是用非常简单的知识点,只要懂得怎么写JavaScript的行内样式就可以判断. 大家应该还记得JavaScript行内样式怎么写吧?(看来我是 ...
- POJ1474:Video Surveillance(求多边形的核)(占位)
A friend of yours has taken the job of security officer at the Star-Buy Company, a famous depart- me ...
- ●poj 1474 Video Surveillance
题链: http://poj.org/problem?id=1474 题解: 计算几何,半平面交 半平面交裸题,快要恶心死我啦... (了无数次之后,一怒之下把onleft改为onright,然后还加 ...
- 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 (半平面交-求核)
pro:顺时针给定多边形,问是否可以放一个监控,可以监控到所有地方,即问是否存在多边形的核. 此题如果两点在同一边界上(且没有被隔段),也可以相互看到. sol:求多边形是否有核.先给直线按角度排序, ...
- poj 1474 Video Surveillance 【半平面交】
半平面交求多边形的核,注意边是顺时针给出的 //卡精致死于是换(?)了一种求半平面交的方法-- #include<iostream> #include<cstdio> #inc ...
随机推荐
- sencha touch
download http://www.sencha.com/products/touch/thank-you/ Developer Center http://developer.sencha.co ...
- AJAX技术的核心
//创建一个XMLHttpRequest对象 ,利用此对象与服务器进行通信 是AJAX技术的核心 /** * 获取XmlHttpRequest对象 */ function getXMLHttpRequ ...
- fatal error C1853
http://myswirl.blog.163.com/blog/static/513186422011827105224739/ 预编译头文件来自编译器的早期版本,或者预编译头为 C++ 而在 C ...
- Hadoop集群系类文章
http://www.cnblogs.com/xia520pi/archive/2012/04/08/2437875.html 后续文章地址:http://www.xiapistudio.com/ta ...
- uva 12654
dp,用优先队列存,上个节点节点覆盖下来的长度: 不过还不是很明白: #include<cstdio> #include<queue> #include<algorith ...
- LINUX Shell 下求两个文件交集和差集的办法
http://blog.csdn.net/autofei/article/details/6579320 假设两个文件FILE1和FILE2用集合A和B表示,FILE1内容如下: a b c e d ...
- SQL SERVER查看当前连接情况
使用超级管理员账户登录,并执行以下命令: SELECT * FROM [Master].[dbo].[SYSPROCESSES] WHERE [DBID] IN ( SELECT [DBID] FRO ...
- TC Asia Competition
250PT不说了.很水得一题. 500PT 给定n(<=1e18),求最大的因子,且这个因子为完全平方,假设这个因子为x那么满足x*x*y = n, 一直枚举因子到n^(1/3)就可以了. 最后 ...
- *[topcoder]HexagonalBoard
http://community.topcoder.com/stat?c=problem_statement&pm=12784 真心觉得tc的div1 250不少好题,对我来说比较适合.这道题 ...
- Visual Assist X
老师推荐的一款vc++6.0插件 visual assistx_百度百科 http://baike.baidu.com/view/4439152.htm?fr=aladdin 下载 VC++6.0助手 ...