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的时候 ...
随机推荐
- 编译@Override报错
有时候Java的Eclipse工程换一台电脑后编译总是@override报错,把@override去掉就好了,但不能从根本上解决问题,因为有时候有@override的地方超级多. 这是jdk的问题,@ ...
- 从零单排c++ primer(17)
(1)假设一个名字在派生类的作用域内无法正确解析,则编译器将继续在外层的基类作用域中寻找该名字的定义. (2)派生类的成员将隐藏同名的基类成员. (3)除了覆盖继承而来的虚函数之外,派生类最好不要重用 ...
- QT的信号与槽机制介绍
信号与槽作为QT的核心机制在QT编程中有着广泛的应用,本文介绍了信号与槽的一些基本概念.元对象工具以及在实际使用过程中应注意的一些问题. QT是一个跨平台的C++ GUI应用构架,它提供了丰富的窗 ...
- VS项目属性配置实验过程
(原创,转载注明出处:http://www.cnblogs.com/binxindoudou/p/4017975.html ) 一.实验背景 cocos2d-x已经发展的相对完善了,从项目的创建.编译 ...
- 中国剩余定理模板poj1006
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #i ...
- MsSql省市联动表
drop table area CREATE TABLE [dbo].[Area] ( , ) NOT NULL , ) COLLATE Chinese_PRC_CI_AS NOT NULL , ) ...
- javascript原型prototype的一个你不一定知道的理解
原型和原型链的故事 相关文章: 为什么原型继承很重要 先来看看一段小代码用以引入要讲的小故事. function Foo() {}; var f1 = new Foo(); Foo.prototype ...
- springmvc常见注解模式
常用注解元素 @Controller 标注在Bean的类定义处 @RequestMapping 真正让Bean具备 Spring MVC Controller 功能的是 @RequestMapping ...
- asp.net 中的那些编译错误(1):控件包含代码块(即<% ... %>),因此无法修改控件集合
在编译页面的时候出现:控件包含代码块(即 <% ... %>),因此无法修改控件集合错误 一般原因是: 在<head runat="server">< ...
- YII数据库增删查改操作
初学YII, 整理了一些YII数据库的相关操作, 共同学习,共同进步. 一.查询数据集合 //1.该方法是根据一个条件查询一个集合 $admin=Admin::model()->findAll ...