POJ 1474 Video Surveillance 半平面交/多边形核是否存在
http://poj.org/problem?id=1474
解法同POJ 1279 A一送一 缺点是还是O(n^2) ...nlogn的过几天补上...
/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std; #define EPS 1e-8
#define MAXN 10005
#define MOD (int)1e9+7
#define PI acos(-1.0)
#define INF ((1LL)<<50)
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max3(a,b,c) (max(max(a,b),c))
#define min3(a,b,c) (min(min(a,b),c))
#define BUG cout<<"BUG! "<<endl
#define LLINE cout<<"------------------"<<endl
#define L(t) (t << 1)
#define R(t) (t << 1 | 1)
#define Mid(a,b) ((a + b) >> 1)
#define lowbit(a) (a & -a)
#define FIN freopen("in.txt","r",stdin)
#pragma comment (linker,"/STACK:102400000,102400000") // typedef long long LL;
// typedef unsigned long long ULL;
// typedef __int64 LL;
// typedef unisigned __int64 ULL;
// int gcd(int a,int b){ return b?gcd(b,a%b):a; }
// int lcm(int a,int b){ return a*b/gcd(a,b); } /********************* F ************************/
struct POINT{
double x,y;
POINT(double _x = , double _y = ):x(_x),y(_y){}
}p[MAXN],q[MAXN],t[MAXN];
int n;
struct LINE{
double a,b,c;
POINT A,B;
LINE(POINT _a, POINT _b):A(_a),B(_b){
a=B.y-A.y;
b=A.x-B.x;
c=B.x*A.y-A.x*B.y;
}
};
double multiply(POINT sp,POINT ep,POINT op){ //叉积 左+ 右-
return (sp.x-op.x) * (ep.y-op.y) - (ep.x-op.x) * (sp.y-op.y);
}
POINT Intersection(LINE a,LINE b){ //直线交点
double u = fabs(b.A.x * a.a + b.A.y * a.b + a.c);
double v = fabs(b.B.x * a.a + b.B.y * a.b + a.c);
POINT t;
t.x = (b.A.x * v + b.B.x * u) / (u + v);
t.y = (b.A.y * v + b.B.y * u) / (u + v);
return t;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("outm.txt","w",stdout);
int ct = ;
while(cin>>n && n){
for(int i = ; i < n ; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
//暴力对每一个向量作半平面交 ...即将右侧的点和与其他直线的交点加入集合
for(int i = ; i < n ; i++) q[i] = p[i];
int cnt = n;
for(int i = ; i < n ; i++){
int c = ;
for(int j = ; j < cnt ; j++){
//点在右侧
if(multiply(p[i],p[(i+)%n],q[j]) <= EPS) {
t[c++] = q[j];
}else { //点在左侧,但是前后线段和该直线有交点
//这个顺序不要写反,否则不是顺时针会WA
if(multiply(p[i],p[(i+)%n],q[(j-+cnt)%cnt]) < -EPS){
t[c++] = Intersection(LINE(p[i],p[(i+)%n]) , LINE(q[j],q[(j-+cnt)%cnt]));
}
if(multiply(p[i],p[(i+)%n],q[(j+)%cnt]) < -EPS){
t[c++] = Intersection(LINE(p[i],p[(i+)%n]) , LINE(q[j],q[(j+)%cnt]));
}
}
}
for(int j = ; j < c ; j++) {q[j] = t[j];}
cnt = c;
}
cout<<"Floor #"<<ct++<<endl;
if(cnt != ) cout<<"Surveillance is possible.\n"<<endl;
else cout<<"Surveillance is impossible.\n"<<endl;
}
return ;
}
POJ 1474 Video Surveillance 半平面交/多边形核是否存在的更多相关文章
- 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 【半平面交】
半平面交求多边形的核,注意边是顺时针给出的 //卡精致死于是换(?)了一种求半平面交的方法-- #include<iostream> #include<cstdio> #inc ...
- ●poj 1474 Video Surveillance
题链: http://poj.org/problem?id=1474 题解: 计算几何,半平面交 半平面交裸题,快要恶心死我啦... (了无数次之后,一怒之下把onleft改为onright,然后还加 ...
- POJ1474 Video Surveillance(半平面交)
求多边形核的存在性,过了这题但是过不了另一题的,不知道是模板的问题还是什么,但是这个模板还是可以过绝大部分的题的... #pragma warning(disable:4996) #include & ...
- POJ 1279 Art Gallery 半平面交求多边形核
第一道半平面交,只会写N^2. 将每条边化作一个不等式,ax+by+c>0,所以要固定顺序,方便求解. 半平面交其实就是对一系列的不等式组进行求解可行解. 如果某点在直线右侧,说明那个点在区域内 ...
- 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 ...
随机推荐
- UVa 208 Firetruck【回溯】
题意:给出一个n个节点的无向图,以及某个节点k,按照字典序从小到大输出从节点1到节点k的所有路径 看的题解 http://blog.csdn.net/hcbbt/article/details/975 ...
- Mojom IDL and Bindings Generator
Mojom IDL and Bindings Generator This document is a subset of the Mojo documentation. Contents Overv ...
- Windows下使用VS的ADO访问MySQL
数据库的访问的一种方式就是:CS结构.即使用TCP/UDP协议进行远程访问,而数据库对于服务端的软件是本地访问!这种管理方式比较常见. 这里主要叙述Windows访问本地数据库的方法. 需要了解几个概 ...
- 20180929 北京大学 人工智能实践:Tensorflow笔记02
https://www.bilibili.com/video/av22530538/?p=16 https://www.bilibili.com/video/av22530538/?p=14 (完)
- 从头认识java-18.2 主要的线程机制(5)-守护线程与非守护线程
这一章节我们来讨论一下守护线程与非守护线程. 1.什么是守护线程?什么是非守护线程? 非守护线程:Java虚拟机在它全部非守护线程已经离开后自己主动离开. 守护线程:守护线程则是用来服务用户线程的,假 ...
- Windows App开发之文件与数据
读取文件和目录名 这一节開始我们将陆续看到Windows App是如何操作文件的. 在Windows上读取文件名称.目录名 首先我们在XAML中定义一个Button和TextBlock,将读取文件/目 ...
- UINavigationBar的系统渲染方式
昨天想手工实现一下类知乎日报的Navigation Bar的动态颜色改变,但不管怎么设置Navigation Bar的 backgroundColor barTintColor alpha參数都达不到 ...
- BZOJ3875: [Ahoi2014&Jsoi2014]骑士游戏
[传送门:BZOJ3875] 简要题意: 给出n种怪物,每种怪物都带有三个值,S[i],K[i],R[i],分别表示对他使用普通攻击的花费,使用魔法攻击的花费,对他使用普通攻击后生成的其他怪物. 每种 ...
- Ubuntu 安装软件和centos 对比命令
之前都是使用Redhat 或者Centos 等rpm的linux ,开始使用ubuntu 很不习惯 1. 安装命令Centos : yum install httpd ...
- Gym - 100625D Destination Unknown 最短路
http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...