题意

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. 开机自动mount

    root权限编辑:/etc/fstab vim /etc/fstab #当前系统里的唯一标志  挂载到什么地方   文件系统类型    选项               是否dump # <fi ...

  2. 差看windows上进程及线程

    转自:http://blog.csdn.net/swgsunhj/article/details/29552027 下载process exlporer: http://technet.microso ...

  3. QMesageBox的使用

    一.使用构造函数弹出对话框 1. QMessageBox msgBox://最简单的对话框,里面什么也没有 QString str = “test”: msgBox.setText(str); msg ...

  4. Oracle数据库PLSQL的中文乱码显示全是问号

    plsql连接数据库乱码问题 缘由: 小师妹周末叫我帮她重装数据库,这么大好的周末时光不出去玩儿,给她装数据库这不是很蛋疼么. 我问她为什么要重装,她说:数据存入数据库后,中文字符有乱码,一定是我上次 ...

  5. mysql一次性删除所有表而不删除数据库

    1.执行如下语句获取删除语句 SELECT CONCAT( 'drop table ', table_name, ';' ) from information_schema.tables where ...

  6. UVA 10288 Coupons (概率)

    题意:有n种纸片无限张,随机抽取,问平均情况下抽多少张可以保证抽中所有类型的纸片 题解:假设自己手上有k张,抽中已经抽过的概率为 s=k/n:那抽中下一张没被抽过的纸片概率为 (再抽一张中,两张中,三 ...

  7. Java 多线程 - 转载

    下面是Java线程相关的热门面试题,你可以用它来好好准备面试. 1) 什么是线程? 线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位.程序员可以通过它进行多处理器编 ...

  8. NumPy Matplotlib库

    NumPy - Matplotlib Matplotlib 是 Python 的绘图库. 它可与 NumPy 一起使用,提供了一种有效的 MatLab 开源替代方案. 它也可以和图形工具包一起使用,如 ...

  9. C++ 进阶学习 ——模板

    模板和重载类似,比重载更省事 通常有两种形式:函数模板和类模板: 函数模板针对仅参数类型不同的函数: 类模板针对仅数据成员和成员函数类型不同的类. 一个简单的函数模板 template <cla ...

  10. JavaScript全屏显示

    JavaScript全屏显示 需要引入的库 https://cdn.bootcss.com/jquery/1.9.0/jquery.min.js https://cdn.bootcss.com/scr ...