LA2797 Monster Trap
题意
分析
可以考虑建图,跑迷宫。
然后以线段端点,原点,和无穷大点建图,有边的条件是两点连线和墙没有交点。
但是对两个线段的交点处理就会有问题,所以把线段延长。另外还需要判断延长后在墙上,舍去这些端点。
时间复杂度\(O(T n^3)\)
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
rg T data=0;
rg int w=1;
rg char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
{
data=data*10+ch-'0';
ch=getchar();
}
return data*w;
}
template<class T>T read(T&x)
{
return x=read<T>();
}
using namespace std;
typedef long long ll;
co double eps=1e-12;
double dcmp(double x)
{
return fabs(x)<eps?0:(x<0?-1:1);
}
struct Point
{
double x,y;
Point(double x=0,double y=0)
:x(x),y(y){}
bool operator<(co Point&p)co
{
return x<p.x||(x==p.x&&y<p.y);
}
bool operator==(co Point&p)co
{
return x==p.x&&y==p.y;
}
};
typedef Point Vector;
Vector operator+(co Vector&A,co Vector&B)
{
return Vector(A.x+B.x,A.y+B.y);
}
Vector operator-(co Point&A,co Point&B)
{
return Vector(A.x-B.x,A.y-B.y);
}
Vector operator*(co Point&A,double v)
{
return Vector(A.x*v,A.y*v);
}
Vector operator/(co Point&A,double v)
{
return Vector(A.x/v,A.y/v);
}
double Cross(co Vector&A,co Vector&B)
{
return A.x*B.y-A.y*B.x;
}
double Dot(co Vector&A,co Vector&B)
{
return A.x*B.x+A.y*B.y;
}
double Length(co Vector&A)
{
return sqrt(Dot(A,A));
}
bool SegmentProperIntersection(co Point&a1,co Point&a2,co Point&b1,co Point&b2)
{
double c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1),
c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0;
}
bool OnSegment(co Point&p,co Point&a1,co Point&a2)
{
return dcmp(Cross(a1-p,a2-p))==0&&dcmp(Dot(a1-p,a2-p))<0;
}
co int MAXV=202;
int V;
int G[MAXV][MAXV],vis[MAXV];
bool dfs(int u)
{
if(u==1)
return 1;
vis[u]=1;
for(int v=0;v<V;++v)
if(G[u][v]&&!vis[v]&&dfs(v))
return 1;
return 0;
}
co int MAXN=100;
int n;
Point p1[MAXN],p2[MAXN];
bool OnAnySegment(Point p)
{
for(int i=0;i<n;++i)
if(OnSegment(p,p1[i],p2[i]))
return 1;
return 0;
}
bool IntersectWithAnySegment(Point a,Point b)
{
for(int i=0;i<n;++i)
if(SegmentProperIntersection(a,b,p1[i],p2[i]))
return 1;
return 0;
}
bool find_path()
{
vector<Point>vertices;
vertices.push_back(Point(0,0));
vertices.push_back(Point(1e5,1e5));
for(int i=0;i<n;++i)
{
if(!OnAnySegment(p1[i]))
vertices.push_back(p1[i]);
if(!OnAnySegment(p2[i]))
vertices.push_back(p2[i]);
}
V=vertices.size();
for(int i=0;i<V;++i)
fill(G[i],G[i]+V,0);
fill(vis,vis+V,0);
for(int i=0;i<V;++i)
for(int j=i+1;j<V;++j)
if(!IntersectWithAnySegment(vertices[i],vertices[j]))
G[i][j]=G[j][i]=1;
return dfs(0);
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
while(read(n))
{
for(int i=0;i<n;++i)
{
int x1,y1,x2,y2;
read(x1),read(y1),read(x2),read(y2);
Point a=Point(x1,y1);
Point b=Point(x2,y2);
Vector v=b-a;
v=v/Length(v);
p1[i]=a-v*1e-6;
p2[i]=b+v*1e-6;
}
puts(find_path()?"no":"yes");
}
return 0;
}
LA2797 Monster Trap的更多相关文章
- LA 2797 (平面直线图PLSG) Monster Trap
题意: 平面上有n条线段,一次给出这n条线段的两个端点的坐标.问怪兽能否从坐标原点逃到无穷远处.(两直线最多有一个交点,且没有三线共交点的情况) 分析: 首先说明一下线段的规范相交:就是交点唯一而且在 ...
- uvalive 2797 Monster Trap
题意:给定一些线段障碍,判断怪物能不能逃离到无穷远处. 思路:从(0,0)点能否到无穷远处.用BFS搜索.那满足什么样的点符合要求,能加入到图中呢? 遍历每个点,显然一开始已经在某些线段上的点要删去. ...
- [GodLove]Wine93 Tarining Round #10
比赛链接: http://www.bnuoj.com/v3/contest_show.php?cid=4159 题目来源: lrj训练指南---几何算法 Flag ID Title A Board ...
- linux shell trap的使用
原文地址:http://blog.sina.com.cn/s/blog_62eb16bb01014dbh.html 一. trap捕捉到信号之后,可以有三种反应方式: (1)执行一段程序来处理这一信号 ...
- Alignment trap 解决方法 【转 结合上一篇
前几天交叉编译crtmpserver到arm9下.编译通过,但是运行的时候,总是提示Alignment trap,但是并不影响程序的运行.这依然很令人不爽,因为不知道是什么原因引起的,这就像一颗定时炸 ...
- ARMLinux下Alignment trap的一些测试 【转自 李迟的专栏 CSDN http://blog.csdn.net/subfate/article/details/7847356
项目中有时会遇到字节对齐的问题,英文为“Alignment trap”,如果直译,意思为“对齐陷阱”,不过这个说法不太好理解,还是直接用英文来表达. ARM平台下一般是4字节对齐,可以参考文后的给出的 ...
- Xcode 自动升级到8.21后坑-Abort trap: 6
pod install or pod update show this message:Generating Pods project Abort trap: 6solve method: udo g ...
- Xcode8 pod install 报错 “Generating Pods project Abort trap
Xcode8 pod install 报错 "Generating Pods project Abort trap 今天在写一个新项目的时候,使用cocoapods在执行 $ pod ins ...
- hdu4950 Monster (水题)
4950 Monster Monster Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
随机推荐
- Centos6.5安装python2.7与pip
安装Python2.7 安装环境 [root@localhost1 ~]# cat /etc/redhat-release CentOS release 6.5 (Final) [root@local ...
- 使用John the ripper工具来尝试破解Linux密码
这篇文章主要介绍了使用John the ripper工具来尝试破解Linux密码的方法,这款工具可能主要被用来破解系统用户的密码以获得文件操作权限,需要的朋友可以参考下 John有别于Hdra之类的工 ...
- java获取当前文件路径 [转]
1.如何获得当前文件路径 常用: 字符串类型:System.getProperty("user.dir"); 综合: package com.zcjl.test.base; imp ...
- Sublime Text3 使用记录
Sublime Text 3 使用记录 来看下本文的大纲吧 介绍下,我的环境 操作系统:win10 64bit sublime Text 3 版本:3143 那么就开始啦. 一. ...
- Rotate Image,N*N矩阵顺时针旋转90度
public class RotateImage { public void rotate(int[][] matrix) { if(matrix.length == 1 && mat ...
- Java小程序之输出星号
题目:打印出如下图案(菱形) * *** ****** ******** ****** *** * 编程工具使用eclipse 代码如下: package test; pu ...
- Ubuntu16.04 Kdevelop汉化及配置
关闭Kdevelop sudo apt-get install kdevelop-l10n 再打开. 字体选择 Sans Serif :style:Normal:这样更舒服且不影响中文的排版,如何改成 ...
- B/S,C/S简单介绍
B/S,C/S 架构 硬件环境不同:C/S 一般建立在专用的网络上, 小范围里的网络环境, 局域网之间再通过专门服务器提供连接和数据交换服务. B/S 建立在广域网之上的, 不必是专门的网络硬件环境, ...
- eclipse indigo 安装 Eclipse Marketplace Client
打开 eclipse,help--Eclipse Marketplace Client就能找到 有的eclipse中没有这个功能就需手动添加Eclipse Marketplace Client. he ...
- IOS-SQLite3的封装
IWStudent.h // // IWStudent.h // 02-SQLite的封装 // // Created by apple on 14-5-22. // Copyright (c) 20 ...