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 ...
随机推荐
- 2062326 齐力锋 实验四《Java面向对象程序设计Android开发》实验报告
北京电子科技学院(BESTI) 实 验 报 告 课程: 程序设计与数据结构 班级: 1623 姓名: 齐力锋 学号: 20162326 成绩: 指导教师: 娄嘉鹏/王志强 实验日期: 2017年5 ...
- 0927-转载:SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
这篇文章暂时只对框架中所要用到的配置文件进行解释说明,而且是针对注解形式的,框架运转的具体流程过两天再进行总结. spring+springmvc+mybatis框架中用到了三个XML配置文件:web ...
- 剑指offer题解02-10
02 单例模式 单例模式,是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例的特殊类.通过单例模式可以保证系统中,应用该模式的类一个类只有一个实例.即一个类只有一个对象实例. 从具体实现角 ...
- Remove Duplicates from Sorted List ,除去链表中相邻的重复元素
Remove Duplicates from Sorted List : Given a sorted linked list, delete all duplicates such that eac ...
- LeetCode第[17]题(Java):Letter Combinations of a Phone Number
题目:最长公共前缀 难度:EASY 题目内容: Given a string containing digits from 2-9 inclusive, return all possible let ...
- selenium学习笔记(webdriver下载配置)
selenium安装后默认安装firefox可以直接使用,当然可以通过其它浏览器 博主这里整理了:chrome . IE 首先是下载地址 http://docs.seleniumhq.org/down ...
- f5 ddos cc——Mitigating DDoS Attacks with F5 Technology
摘自:https://f5.com/resources/white-papers/mitigating-ddos-attacks-with-f5-technology Mitigating Appli ...
- iOS自动化探索(一)WebDriverAgent安装
WebDriverAgent FaceBook推出的一款iOS移动测试框架, 支持真机和模拟器, 同时支持USB, 官方是这样介绍的: https://github.com/facebook/WebD ...
- Node——用http-proxy 做反向代理服务器
时下不少场景,都是申请一个 VPS 主机来托管运行 Web 项目的,小弟我也不例外——购买了一个小型的 CentOS VPS 使用着.在使用的过程中,面临一个问题,就是同一类型的服务端环境还好——但如 ...
- MVC 框架中的缓存
在程序中加入缓存的目的很多是为了提高程序的性能,提高数据的查找效率,在MVC框架中也引入了非常多的缓存,比如Controller的匹配查找,Controller,ControllerDescripto ...