题意

PDF

分析

可以考虑建图,跑迷宫。

然后以线段端点,原点,和无穷大点建图,有边的条件是两点连线和墙没有交点。

但是对两个线段的交点处理就会有问题,所以把线段延长。另外还需要判断延长后在墙上,舍去这些端点。

时间复杂度\(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的更多相关文章

  1. LA 2797 (平面直线图PLSG) Monster Trap

    题意: 平面上有n条线段,一次给出这n条线段的两个端点的坐标.问怪兽能否从坐标原点逃到无穷远处.(两直线最多有一个交点,且没有三线共交点的情况) 分析: 首先说明一下线段的规范相交:就是交点唯一而且在 ...

  2. uvalive 2797 Monster Trap

    题意:给定一些线段障碍,判断怪物能不能逃离到无穷远处. 思路:从(0,0)点能否到无穷远处.用BFS搜索.那满足什么样的点符合要求,能加入到图中呢? 遍历每个点,显然一开始已经在某些线段上的点要删去. ...

  3. [GodLove]Wine93 Tarining Round #10

    比赛链接: http://www.bnuoj.com/v3/contest_show.php?cid=4159 题目来源: lrj训练指南---几何算法 Flag ID Title   A Board ...

  4. linux shell trap的使用

    原文地址:http://blog.sina.com.cn/s/blog_62eb16bb01014dbh.html 一. trap捕捉到信号之后,可以有三种反应方式: (1)执行一段程序来处理这一信号 ...

  5. Alignment trap 解决方法  【转 结合上一篇

    前几天交叉编译crtmpserver到arm9下.编译通过,但是运行的时候,总是提示Alignment trap,但是并不影响程序的运行.这依然很令人不爽,因为不知道是什么原因引起的,这就像一颗定时炸 ...

  6. ARMLinux下Alignment trap的一些测试 【转自 李迟的专栏 CSDN http://blog.csdn.net/subfate/article/details/7847356

    项目中有时会遇到字节对齐的问题,英文为“Alignment trap”,如果直译,意思为“对齐陷阱”,不过这个说法不太好理解,还是直接用英文来表达. ARM平台下一般是4字节对齐,可以参考文后的给出的 ...

  7. Xcode 自动升级到8.21后坑-Abort trap: 6

    pod install or pod update show this message:Generating Pods project Abort trap: 6solve method: udo g ...

  8. Xcode8 pod install 报错 “Generating Pods project Abort trap

    Xcode8 pod install 报错 "Generating Pods project Abort trap 今天在写一个新项目的时候,使用cocoapods在执行 $ pod ins ...

  9. hdu4950 Monster (水题)

    4950 Monster Monster Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...

随机推荐

  1. 2018-2019-2 20165114《网络对抗技术》Exp2 后门原理与实践

    目录 一.实验准备 二.实验内容 三.基础问题回答 四.实验过程及步骤 五.实验总结与体会 六.实验中遇到的问题与错误. 一.实验准备 1.后门概念 后门就是不经过正常认证流程而访问系统的通道. 哪里 ...

  2. C++中 int main(int argc, char **argv) 命令行传递参数

    C++中,比较常见的是不带参数的主函数int main(),如果使用命令行执行程序,主函数也可以接收预先输入的参数,形式如下. int main(int argc,char **argv) argc: ...

  3. Cisco交换机设备配置镜像端口

    查看交换机端口的基本情况,输入命令 show ip int bri,可以查看端口状态 FastEthernet表示百兆以太网端口,GigabitEthernet表示千兆以太网端口. 进入全局模式 设置 ...

  4. python中set的用处

    python中有很多不同的数据结构,比如list,tuple,set,dic等,为什么我要单独讲set呢. 因为set是一个比较容易被遗忘的数据结构,不光在python中,在C++中也一样,反正我是很 ...

  5. java中string与byte[]之间的转化分析

    背景:最近接触zookeeper的java开发,由于zookeeper中传的好像都是byte[]的数据(需要进一步确认),好多情况下都需要进行转换. 1)和zookeeper原生API不同,通过zkc ...

  6. AngularJS的思考

    AngularJS实践 什么是AngularJS AngularJS的核心理念是什么? 在我看来,Angualr的核心思想是:Template + Scope => HTML, Template ...

  7. var与this定义变量的区别以及疑惑

    我们知道: var可以定义一个局部变量,当然如果var定义在最外层的话,就是全局的局部变量,也就算是全局变量了. 而this关键字定义的变量准确的说应该算是成员变量.即定义的是调用对象的成员变量. 另 ...

  8. webstorm打开带有node_modules文件夹的工程时很卡

    ctrl+alt+s打开settings 在webstorm中配置这个就可以不加载出来node_modules使页面加载快

  9. SpringCloud之eureka服务注册和服务发现

    服务注册中心 :eureka-server 作用:服务注册中心提供服务注册功能 服务提供方:eureka-client 作用:注册服务到服务注册中心 服务注册中心 :eureka-server 创建 ...

  10. CheckBox复选框控件

    CheckBox复选框控件 一.简介 1. 2.类结构图 二.CheckBox复选框控件使用方法 这里是使用java代码在LinearLayout里面添加控件 1.新建LinearLayout布局 2 ...