poj 1066 Treasure Hunt
http://poj.org/problem?id=1066
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#define maxn 500000
using namespace std; const double eps=1e-;
const int inf=<<;
int t1,t2,t3,t4,t5,c; int cmp(double x)
{
if(fabs(x)<eps) return ;
if(x>) return ;
return -;
} struct point
{
double x,y;
point() {}
point(double a,double b):x(a),y(b) {}
friend point operator -(const point &a,const point &b)
{
return point(a.x-b.x,a.y-b.y);
}
friend point operator *(const point &a,const double &b)
{
return point(a.x*b,a.y*b);
}
friend point operator /(const point &a,const double &b)
{
return point(a.x/b,a.y/b);
}
} p[maxn];
point m[][]; int cmp1(const point &a,const point &b)
{
return a.x<b.x;
} int cmp2(const point &a,const point &b)
{
return a.y<b.y;
} struct line
{
point a,b;
line() {}
line(point x,point y):a(x),b(y) {};
} ll[maxn]; double det(const point &a,const point &b)
{
return a.x*b.y-a.y*b.x;
} bool segment(point a1,point a2,point b1,point b2)
{
double c1=det(a2-a1,b1-a1),c2=det(a2-a1,b2-a1);
double c3=det(b2-b1,a1-b1),c4=det(b2-b1,a2-b1);
return cmp(c1)*cmp(c2)<&&cmp(c3)*cmp(c4)<;
} void make(double x,double y)
{
if(y==)
{
m[][t1].x=x;
m[][t1++].y=y;
}
else if(y==)
{
m[][t2].x=x;
m[][t2++].y=y;
}
else if(x==)
{
m[][t3].x=x;
m[][t3++].y=y;
}
else if(x==)
{
m[][t4].x=x;
m[][t4++].y=y;
}
} void inti()
{
for(int i=; i<=t1; i++)
{
p[c].x=(m[][i].x+m[][i-].x)/;
p[c++].y=;
}
for(int i=; i<=t3; i++)
{
p[c].y=(m[][i].y+m[][i-].y)/;
p[c++].x=;
}
for(int i=; i<=t2; i++)
{
p[c].x=(m[][i].x+m[][i-].x)/;
p[c++].y=;
}
for(int i=; i<=t4; i++)
{
p[c].y=(m[][i].y+m[][i-].y)/;
p[c++].x=;
}
}
int main()
{
int T;
while(scanf("%d",&T)!=EOF)
{
int n=T;
double x1,y1,x2,y2;
t1=,t2=,t3=,t4=,t5=;
c=;
while(T--)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
make(x1,y1);
make(x2,y2);
point st(x1,y1);
point st1(x2,y2);
ll[t5].a=st;
ll[t5++].b=st1;
}
m[][].x=;
m[][].y=;
m[][t1].x=;
m[][t1].y=;
m[][t3].x=;
m[][t3].y=;
m[][].x=;
m[][].y=;
m[][].x=;
m[][].y=;
m[][t2].x=;
m[][t2].y=;
m[][].x=;
m[][].y=;
m[][t4].x=;
m[][t4].y=;
sort(m[],m[]+t1+,cmp1);
sort(m[],m[]+t2+,cmp1);
sort(m[],m[]+t3+,cmp2);
sort(m[],m[]+t4+,cmp2);
inti();
point pp,p1;
scanf("%lf%lf",&pp.x,&pp.y);
int ans=inf;
for(int i=; i<c; i++)
{
line l1(p[i],pp);
int ans1=;
for(int j=; j<t5; j++)
{
if(segment(l1.a,l1.b,ll[j].a,ll[j].b)) ans1++;
}
ans=min(ans,ans1);
}
if(n==)
{
ans=;
}
printf("Number of doors = %d\n",ans+);
}
return ;
}
poj 1066 Treasure Hunt的更多相关文章
- poj 1066 Treasure Hunt (Geometry + BFS)
1066 -- Treasure Hunt 题意是,在一个金字塔中有一个宝藏,金字塔里面有很多的墙,要穿过墙壁才能进入到宝藏所在的地方.可是因为某些原因,只能在两个墙壁的交点连线的中点穿过墙壁.问最少 ...
- POJ 1066 Treasure Hunt(线段相交判断)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4797 Accepted: 1998 Des ...
- POJ 1066 Treasure Hunt(相交线段&&更改)
Treasure Hunt 大意:在一个矩形区域内.有n条线段,线段的端点是在矩形边上的,有一个特殊点,问从这个点到矩形边的最少经过的线段条数最少的书目,穿越仅仅能在中点穿越. 思路:须要巧妙的转换一 ...
- POJ 1066 - Treasure Hunt - [枚举+判断线段相交]
题目链接:http://poj.org/problem?id=1066 Time Limit: 1000MS Memory Limit: 10000K Description Archeologist ...
- POJ 1066 Treasure Hunt [想法题]
题目链接: http://poj.org/problem?id=1066 --------------------------------------------------------------- ...
- POJ 1066 Treasure Hunt (线段相交)
题意:给你一个100*100的正方形,再给你n条线(墙),保证线段一定在正方形内且端点在正方形边界(外墙),最后给你一个正方形内的点(保证不再墙上) 告诉你墙之间(包括外墙)围成了一些小房间,在小房间 ...
- POJ 1066 Treasure Hunt【线段相交】
思路:枚举四边墙的门的中点,与终点连成一条线段,判断与其相交的线段的个数.最小的加一即为答案. 我是傻逼,一个数组越界调了两个小时. #include<stdio.h> #include& ...
- POJ 1066 Treasure Hunt --几何,线段相交
题意: 正方形的房子,给一些墙,墙在区域内是封闭的,给你人的坐标,每穿过一道墙需要一把钥匙,问走出正方形需要多少把钥匙. 解法: 因为墙是封闭的,所以绕路也不会减少通过的墙的个数,还不如不绕路走直线, ...
- 简单几何(线段相交) POJ 1066 Treasure Hunt
题目传送门 题意:从四面任意点出发,有若干障碍门,问最少要轰掉几扇门才能到达终点 分析:枚举入口点,也就是线段的两个端点,然后选取与其他线段相交点数最少的 + 1就是答案.特判一下n == 0的时候 ...
随机推荐
- 页游AS客户端架构设计历程记录
以下是一个只用JAVA做过服务器架构的程序员做的AS客户端架构,希望大家能推荐好的框架和意见,也求AS高程们的引导,等到基本功能成形后,低调开源,框架可以支持一个中度型页游的开发,本文不断更新中... ...
- NuGet 无法连接到远程服务器-解决方法
一. Entity Framework以下简称EF 安装EF4.3的步骤是首先安装VS扩展 NuGet,然后再使用NuGet安装EF程序包 安装完NuGet就可以安装EF了,有两种方式可以安装EF: ...
- javaScript的使用
<script>XXX</ccript>HTML文件插入js的主要方法.这个标签主要有以下的几个属性: 1,charset:可选.表示通过src属性指定的字符集. 2,defe ...
- inux 安装中文支持包及中文字符集配置 +i18n
由于某些原因系统安装时未安装中文支持,导致后续应用出现中文方块乱码现象, 解决方法很简单,当然不是重装,只需以下三步即可搞定. .安装中文包: yum -y groupinstall chinese- ...
- ios中框架介绍
ios中框架介绍 参考博客: 参考文章:框架介绍 框架介绍 框架就是一个目录,一个目录包含了共享库,访问共享库里面的代码的头文件,和其他的图片和声音的资源文件.一个共享库定义的方法和函数可以被应用程序 ...
- discuz! X3 门户文章添加字段
1. 首先需要去数据表里[llgp_portal_article_title]手动添加需要添加的字段. (注意: 数据表前缀依据自己的设置而定) 2. 修改模版template\default\por ...
- centos7 部署ssserver
centos7 部署shadowsocks服务端 为什么要选centos7? 以后centos7 肯定是主流,在不重要的环境还是尽量使用新系统吧 centos7 的坑 默认可能会有firewall 或 ...
- android背景平铺方式 tileMode
创建重复的背景图片 在drawable目录下创建一个repeat_bg.xml: 然后在布局的xml文件中可以这样引用: ================================ ...
- 把C#对象转换为json字符串
下面的代码写在ashx一般处理程序中 声明context.Response.ContentType = "application/json";代表服务器端返回的数据为json字符串 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...