题目大意:询问是否在家里装一个监视器就可以监控所有的角落。

分析:赤裸裸的判断多边形内核题目。

代码如下:

#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(判断是否存在内核)的更多相关文章

  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. JavaScript,一个超级简单的方法判断浏览器的内核前缀

    先说明,此处的方法是说超级简单的方法,不是指代码超级少,而是用非常简单的知识点,只要懂得怎么写JavaScript的行内样式就可以判断. 大家应该还记得JavaScript行内样式怎么写吧?(看来我是 ...

  4. POJ1474:Video Surveillance(求多边形的核)(占位)

    A friend of yours has taken the job of security officer at the Star-Buy Company, a famous depart- me ...

  5. ●poj 1474 Video Surveillance

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

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

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

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

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

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

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

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

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

随机推荐

  1. Python 学习日志(一)

    第一天: (一)安装Python3.3: (二)试运行: 1.在IDLE中输入:print("Hello,world"); //回车查看结果 2.使用"File" ...

  2. 对于数组使用sizeof(a)和使用sizeof(a[0])

    #include "stdafx.h" #include <iostream> using namespace std; int main() { ]={}; cout ...

  3. CQRS学习——IOC,配置,仓储隔离以及QueryEntry[其三]

    从IoC开始说起 博主最早开始用的IoC容器叫AutoFac,那时候用它主要是为了生命周期管理——将EF上下文的生命周期限定为每请求.当然也总是每每听到IoC的好处,但是仍然不能理解其优势.最近在学习 ...

  4. PHP扩展编写示例

    1.生成描述文件,包含对函数等的定义 [chengyi@localhost php-extension]$ cat hello_cy.def string self_concat(string str ...

  5. MD5算法步骤详解

    转自MD5算法步骤详解 之前要写一个MD5程序,但是从网络上看到的资料基本上一样,只是讲了一个大概.经过我自己的实践,我决定写一个心得,给需要实现MD5,但又不要求很高深的编程知识的童鞋参考.不多说了 ...

  6. mysql查看'datadir'目录

    mysql查看创建的数据库的数据,包含表等存放的目录,可以输入下面指令查看: show variables like 'datadir'

  7. QT 的信号与槽机制介绍

    https://www.ibm.com/developerworks/cn/linux/guitoolkit/qt/signal-slot/ http://www.kuqin.com/qtdocume ...

  8. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-007-定义切面的around advice

    一.注解@AspectJ形式 1. package com.springinaction.springidol; import org.aspectj.lang.ProceedingJoinPoint ...

  9. C#操作Access

    C#操作Access数据库的基础知识浅析 C#操作Access数据库的基础知识都有什么呢? C#操作Access数据库的基础知识1. 通过ADO.NET的OleDb相关类来操作Access 主要知识点 ...

  10. Android开发UI之布局文件LinearLayout

    LinearLayout-线性布局,该布局中的控件按照水平方向排列或者竖直方向排列. 通过属性android:orientation=""决定的,可选值:vertical和hori ...