题意:给定一些线段障碍,判断怪物能不能逃离到无穷远处。

思路:从(0,0)点能否到无穷远处。用BFS搜索。那满足什么样的点符合要求,能加入到图中呢?

遍历每个点,显然一开始已经在某些线段上的点要删去。再判断,两点之间的连线是否与其他线段有交。有则删去。

这道题要注意如果两条线段重合,怎么办?延长每条线段,如果交点在线段内,不算。

 #include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<memory.h>
#include<cstdlib>
#include<vector>
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long int
#define up(i,x,y) for(i=x;i<=y;i++)
#define w(a) while(a)
const double inf=0x3f3f3f3f;
const int N = ;
const double PI = acos(-1.0);
using namespace std;
const double eps = 1e-; double dcmp(double x)
{
if(fabs(x) < eps) return ;
else return x < ? - : ;
} struct Point
{
double x, y;
Point(double x=, double y=):x(x),y(y) { }
}; typedef Point Vector; Vector operator + (const Point& A, const Point& B)
{
return Vector(A.x+B.x, A.y+B.y);
} Vector operator - (const Point& A, const Point& B)
{
return Vector(A.x-B.x, A.y-B.y);
} Vector operator * (const Point& A, double v)
{
return Vector(A.x*v, A.y*v);
} Vector operator / (const Point& A, double v)
{
return Vector(A.x/v, A.y/v);
} double Cross(const Vector& A, const Vector& B)
{
return A.x*B.y - A.y*B.x;
} double Dot(const Vector& A, const Vector& B)
{
return A.x*B.x + A.y*B.y;
} double Length(const Vector& A)
{
return sqrt(Dot(A,A));
} bool operator < (const Point& p1, const Point& p2)
{
return p1.x < p2.x || (p1.x == p2.x && p1.y < p2.y);
} bool operator == (const Point& p1, const Point& p2)
{
return p1.x == p2.x && p1.y == p2.y;
} bool SegmentProperIntersection(const Point& a1, const Point& a2, const Point& b1, const 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)< && dcmp(c3)*dcmp(c4)<;
} bool OnSegment(const Point& p, const Point& a1, const Point& a2)
{
return dcmp(Cross(a1-p, a2-p)) == && dcmp(Dot(a1-p, a2-p)) < ;
} const int maxv = + ;
int V;
int G[maxv][maxv], vis[maxv]; bool dfs(int u)
{
if(u == ) return true; // 1是终点
vis[u] = ;
for(int v = ; v < V; v++)
if(G[u][v] && !vis[v] && dfs(v)) return true;
return false;
} const int maxn = + ;
int n;
Point p1[maxn], p2[maxn]; // 在任何一条线段的中间(在端点不算)
bool OnAnySegment(Point p)
{
for(int i = ; i < n; i++)
if(OnSegment(p, p1[i], p2[i])) return true;
return false;
} // 与任何一条线段规范相交
bool IntersectWithAnySegment(Point a, Point b)
{
for(int i = ; i < n; i++)
if(SegmentProperIntersection(a, b, p1[i], p2[i])) return true;
return false;
} bool find_path()
{
// 构图
vector<Point> vertices;
vertices.push_back(Point(, )); // 起点
vertices.push_back(Point(1e5, 1e5)); // 终点
for(int i = ; i < n; i++)
{
if(!OnAnySegment(p1[i])) vertices.push_back(p1[i]);
if(!OnAnySegment(p2[i])) vertices.push_back(p2[i]);
}
V = vertices.size();
memset(G, , sizeof(G));
memset(vis, , sizeof(vis));
for(int i = ; i < V; i++)
for(int j = i+; j < V; j++)
if(!IntersectWithAnySegment(vertices[i], vertices[j]))
G[i][j] = G[j][i] = ;
return dfs();
} int main()
{
while(cin >> n && n)
{
for(int i = ; i < n; i++)
{
double x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
Point a = Point(x1, y1);
Point b = Point(x2, y2);
Vector v = b - a;
v = v / Length(v);
p1[i] = a + v * 1e-;
p2[i] = b + v * 1e-;
}
if(find_path()) cout << "no\n";
else cout << "yes\n";
}
return ;
}

uvalive 2797 Monster Trap的更多相关文章

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

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

  2. LA2797 Monster Trap

    题意 PDF 分析 可以考虑建图,跑迷宫. 然后以线段端点,原点,和无穷大点建图,有边的条件是两点连线和墙没有交点. 但是对两个线段的交点处理就会有问题,所以把线段延长.另外还需要判断延长后在墙上,舍 ...

  3. [GodLove]Wine93 Tarining Round #10

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

  4. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  5. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  6. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  7. linux shell trap的使用

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

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

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

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

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

随机推荐

  1. Usermod 命令详解

    参考资料:usermod manpage usermod - 修改用户帐户信息 modify a user account usermod [options] user_name usermod 命令 ...

  2. NOI2015考试小结

    这次NOI2015有幸获得金牌考进了国家集训队,意味着我的OI退役时间既省选之后有延迟了好几个月,又有了新的目标吧. 先说一下考试之外的感受吧,学军宿舍很牛X,接待NOIers而不提供插座,唯一可以用 ...

  3. tomcat启动报错:Unsupported major.minor version 51.0

    myeclipse中添加项目后,发现项目启动时报错:Unsupported major.minor version 51.0 因为tomcat使用的jdk版本不支持你项目的jdk版本,需要你在myec ...

  4. hdu 3952

    因为一个小错 不过  好不爽........ #include <iostream> #include <fstream> using namespace std; struc ...

  5. XP纯净版光盘ISO镜像文件

    原版xp的下载地址,直接发链接得了-.-打开迅雷,按新建任务,把下面下载地址复制进来,下载就可以了 thunder://QUFodHRwOi8vc29mdC51c2Fpa2EuY24vstnX98+1 ...

  6. weblogic集群无法启动,提示java.lang.NumberFormatException

    我有两台weblogic9.2做的集群A,B,A是主服务器,B是受管服务器,后来通过脚本启动weblogic服务,A服务启动异常,经查后台的日志文件发现报错消息如下: WebLogic Server ...

  7. linux 5.5 开xmanager远程

    http://bbs.cqsztech.com/dv_rss.asp?s=xhtml&boardid=3&id=11&page=9 linux 5.5 开xmanager远程 ...

  8. SQLite入门与分析(四)---Page Cache之事务处理(2)

    写在前面:个人认为pager层是SQLite实现最为核心的模块,它具有四大功能:I/O,页面缓存,并发控制和日志恢复.而这些功能不仅是上层Btree的基础,而且对系统的性能和健壮性有关至关重要的影响. ...

  9. 92. Reverse Linked List II

    题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1- ...

  10. Android 系统的四层结构

    从上图中可以看出,Android 系统架构为四层结构,从上层到下层分别是应用程序层(Applications). 应用程序框架层 (Application Framework).系统运行库层(Libr ...