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的时候 ...
随机推荐
- keil中for循环变量递减,无法跳出循环的问题
定义j时应注意其变量类型char,此循环当j=0时,再执行一次则keil中j=0XFF,而不是-1,所以无法跳出循环.但在vc6.0中是可以跳出循环的. 解决办法如下:不能让j的值为负数 uchar ...
- Hard 计算0到n之间2的个数 @CareerCup
一种是Brute force,O(nlogn) 另一种是找规律O(n),见http://hawstein.com/posts/20.4.html 当某一位的数字小于2时,那么该位出现2的次数为:更高位 ...
- android:Adb connection Error:远程主机强迫关闭了一个现有的连接
用真机调试程序的时候,eclipse的console总是出现如下的错误“Adb connection Error:远程主机强迫关闭了一个现有的连接” 问题出现的原因:这是ddms调用adb引发的. 经 ...
- ping and traceroute(tracert)
1.ping程序简单介绍 这个程序是Mike Muuss编写的.目的是測试另外一台机子是否可达. 运用的协议就是ICMP.运用的是ICMP的回显应答和请求回显两个类型.曾经呢.能ping通说明可以进行 ...
- Qt 学习之路:视图选择 (QItemSelectionModel)
选择是视图中常用的一个操作.在列表.树或者表格中,通过鼠标点击可以选中某一项,被选中项会变成高亮或者反色.在 Qt 中,选择也是使用了一种模型.在 model/view 架构中,这种选择模型提供了一种 ...
- jQuery代码优化 事件委托篇
<转自 http://www.jb51.net/article/28770.htm> 参考文章: 解密jQuery事件核心 - 绑定设计(一) 参考文章: 解密jQuery事件核心 - ...
- Lambda表达式 简介 语法 示例
Lambda 表达式也称为闭包,是匿名类的简短形式.Lambda 表达式简化了[单一抽象方法声明接口]的使用,因此 lambda 表达式也称为功能接口. 在 Java SE 7 中,单一方法接口可使用 ...
- 移动端屏幕自适应js与rem
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;&qu ...
- Linq101-Element
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Element ...
- eclipse[日文版] 的SVN 上传步骤
可能有些朋友在日企上班,肯定要用到SVN,可是一般就下载和更新,没有用到上传 这里来介绍下上传 1.项目右键 2.点击Share Project 3.点击SVN下一步 4.选择你的上传的服务器地址 5 ...