Treasure Hunt
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4797   Accepted: 1998

Description

Archeologists from the Antiquities and Curios Museum (ACM) have flown to Egypt to examine the great pyramid of Key-Ops. Using state-of-the-art technology they are able to determine that the lower floor of the pyramid is constructed from a series of straightline walls, which intersect to form numerous enclosed chambers. Currently, no doors exist to allow access to any chamber. This state-of-the-art technology has also pinpointed the location of the treasure room. What these dedicated (and greedy) archeologists want to do is blast doors through the walls to get to the treasure room. However, to minimize the damage to the artwork in the intervening chambers (and stay under their government grant for dynamite) they want to blast through the minimum number of doors. For structural integrity purposes, doors should only be blasted at the midpoint of the wall of the room being entered. You are to write a program which determines this minimum number of doors.
An example is shown below:

Input

The
input will consist of one case. The first line will be an integer n (0
<= n <= 30) specifying number of interior walls, followed by n
lines containing integer endpoints of each wall x1 y1 x2 y2 . The 4
enclosing walls of the pyramid have fixed endpoints at (0,0); (0,100);
(100,100) and (100,0) and are not included in the list of walls. The
interior walls always span from one exterior wall to another exterior
wall and are arranged such that no more than two walls intersect at any
point. You may assume that no two given walls coincide. After the
listing of the interior walls there will be one final line containing
the floating point coordinates of the treasure in the treasure room
(guaranteed not to lie on a wall).

Output

Print a single line listing the minimum number of doors which need to be created, in the format shown below.

Sample Input

7
20 0 37 100
40 0 76 100
85 0 0 75
100 90 0 90
0 71 100 61
0 14 100 38
100 47 47 100
54.5 55.4

Sample Output

Number of doors = 2 

Source

 
 
题目是穿过墙的中点出来。其实枚举起点和终点,看中间和多少条线段相交。
 
 
/************************************************************
* Author : kuangbin
* Email : kuangbin2009@126.com
* Last modified : 2013-07-14 21:59
* Filename : POJ1066TreasureHunt.cpp
* Description :
* *********************************************************/ #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <math.h> using namespace std;
const double eps = 1e-;
int sgn(double x)
{
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
}
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x = _x;y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x,y - b.y);
}
//叉积
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
//点积
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
//绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B)
{
double tx = x,ty = y;
x = tx*cos(B) - ty*sin(B);
y = tx*sin(B) + ty*cos(B);
}
};
struct Line
{
Point s,e;
double k;
Line(){}
Line(Point _s,Point _e)
{
s = _s;e = _e;
k = atan2(e.y - s.y,e.x - s.x);
}
//两条直线求交点,
//第一个值为0表示直线重合,为1表示平行,为0表示相交,为2是相交
//只有第一个值为2时,交点才有意义
pair<int,Point> operator &(const Line &b)const
{
Point res = s;
if(sgn((s-e)^(b.s-b.e)) == )
{
if(sgn((s-b.e)^(b.s-b.e)) == )
return make_pair(,res);//重合
else return make_pair(,res);//平行
}
double t = ((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
res.x += (e.x-s.x)*t;
res.y += (e.y-s.y)*t;
return make_pair(,res);
}
};
//两点间距离
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
} bool inter(Line l1,Line l2)
{
return
max(l1.s.x,l1.e.x) >= min(l2.s.x,l2.e.x) &&
max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) &&
max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) &&
max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) &&
sgn((l2.s-l1.s)^(l1.e-l1.s))*sgn((l2.e-l1.s)^(l1.e-l1.s)) <= &&
sgn((l1.s-l2.s)^(l2.e-l1.s))*sgn((l1.e-l2.s)^(l2.e-l2.s)) <= ;
} const int MAXN = ;
Line line[MAXN]; Point s; Point p[MAXN]; int main()
{
int n;
while(scanf("%d",&n)==)
{
double x1,y1,x2,y2;
for(int i = ;i <= n;i++)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
line[i] = Line(Point(x1,y1),Point(x2,y2));
p[*i-] = Point(x1,y1);
p[*i] = Point(x2,y2);
}
scanf("%lf%lf",&x1,&y1);
s = Point(x1,y1);
int ans = ;
for(int i = ;i <= *n;i++)
{
int tmp = ;
Line line1 = Line(s,p[i]);
for(int j = ;j <= n;j++)
if(inter(line1,line[j]))
tmp++;
ans = min(ans,tmp);
}
Line line1;
line1 = Line(s,Point(,));
int tmp = ;
for(int i = ;i <= n;i++)
if(inter(line1,line[i]))
tmp++;
ans = min(ans,tmp+);
line1 = Line(s,Point(,));
tmp = ;
for(int i = ;i <= n;i++)
if(inter(line1,line[i]))
tmp++;
ans = min(ans,tmp+);
line1 = Line(s,Point(,));
tmp = ;
for(int i = ;i <= n;i++)
if(inter(line1,line[i]))
tmp++;
ans = min(ans,tmp+);
line1 = Line(s,Point(,));
tmp = ;
for(int i = ;i <= n;i++)
if(inter(line1,line[i]))
tmp++;
ans = min(ans,tmp+);
printf("Number of doors = %d\n",ans);
} return ;
}
 
 
 

POJ 1066 Treasure Hunt(线段相交判断)的更多相关文章

  1. poj 1066 Treasure Hunt 线段相交

    题目链接 题目描述 一个正方形房间被分成若干个小室,宝藏在其中某一点.现可炸开任意一堵墙壁的中点位置.问至少要炸开多少堵墙才能从外面到达宝藏所在地. 思路 (很巧妙,没想到) 直接枚举墙壁与正方形外壁 ...

  2. POJ 1066 Treasure Hunt(相交线段&amp;&amp;更改)

    Treasure Hunt 大意:在一个矩形区域内.有n条线段,线段的端点是在矩形边上的,有一个特殊点,问从这个点到矩形边的最少经过的线段条数最少的书目,穿越仅仅能在中点穿越. 思路:须要巧妙的转换一 ...

  3. poj 1066 Treasure Hunt (Geometry + BFS)

    1066 -- Treasure Hunt 题意是,在一个金字塔中有一个宝藏,金字塔里面有很多的墙,要穿过墙壁才能进入到宝藏所在的地方.可是因为某些原因,只能在两个墙壁的交点连线的中点穿过墙壁.问最少 ...

  4. POJ 1066 Treasure Hunt (线段相交)

    题意:给你一个100*100的正方形,再给你n条线(墙),保证线段一定在正方形内且端点在正方形边界(外墙),最后给你一个正方形内的点(保证不再墙上) 告诉你墙之间(包括外墙)围成了一些小房间,在小房间 ...

  5. POJ 1066 Treasure Hunt【线段相交】

    思路:枚举四边墙的门的中点,与终点连成一条线段,判断与其相交的线段的个数.最小的加一即为答案. 我是傻逼,一个数组越界调了两个小时. #include<stdio.h> #include& ...

  6. 简单几何(线段相交) POJ 1066 Treasure Hunt

    题目传送门 题意:从四面任意点出发,有若干障碍门,问最少要轰掉几扇门才能到达终点 分析:枚举入口点,也就是线段的两个端点,然后选取与其他线段相交点数最少的 + 1就是答案.特判一下n == 0的时候 ...

  7. POJ 1066 Treasure Hunt(计算几何)

    题意:给出一个100*100的正方形区域,通过若干连接区域边界的线段将正方形区域分割为多个不规则多边形小区域,然后给出宝藏位置,要求从区域外部开辟到宝藏所在位置的一条路径,使得开辟路径所需要打通的墙壁 ...

  8. POJ 1066 - Treasure Hunt - [枚举+判断线段相交]

    题目链接:http://poj.org/problem?id=1066 Time Limit: 1000MS Memory Limit: 10000K Description Archeologist ...

  9. [poj] 1066 Treasure Hunt || 判断直线相交

    原题 在金字塔内有一个宝藏p(x,y),现在要取出这个宝藏. 在金字塔内有许多墙,为了进入宝藏所在的房间必须把墙炸开,但是炸墙只能炸每个房间墙的中点. 求将宝藏运出城堡所需要的最小炸墙数. 判断点和直 ...

随机推荐

  1. R语言将List转为矩阵do.call

    ehparse.matrix <- do.call(rbind, easyham.parse)

  2. springMVC实现多文件上传

    <h2>上传多个文件 实例</h2> <form action="/workreport/uploadMultiFile.html" method=& ...

  3. POJ 2528 (线段树 离散化) Mayor's posters

    离散化其实就是把所有端点放在一起,然后排序去个重就好了. 比如说去重以后的端点个数为m,那这m个点就构成m-1个小区间.然后给这m-1个小区间编号1~m-1,再用线段树来做就行了. 具体思路是,从最后 ...

  4. 抛出自定义异常,spring AOP事务不回滚的解决方案

    spring AOP 默认对RuntimeException()异常或是其子类进行事务回滚,也就是说 事务回滚:throw new RuntimeException("xxxxxxxxxxx ...

  5. Servlet的延迟加载和预加载

    我们什么时候使用了延迟加载呢? 先从hibernate引入这个概念吧. hibernate使用lazy属性设置延迟加载,load方法会使用延迟加载. 举个例子: 一个学生有多部手机,如果使用了延迟加载 ...

  6. PHP学习笔记05——面向对象

    <?php //1. 类的声明(包括构造方法.析构方法) class PersonA { var $name; //成员属性,用var声明 public $age; //当有其他修饰的时候,就不 ...

  7. 06day2

    蠕虫游戏 模拟 [问题描述] 蠕虫是一个古老的电脑游戏,它有许多版本.但所有版本都有一个共同规则:操纵一条蠕虫在屏幕上转圈,并试着去避免撞到自己或障碍物. 这里我们将模拟一个简单的版本.游戏将在 50 ...

  8. 树莓派 Linux 剪贴板

    安装: apt-get install xsel 显示剪贴板中的数据: xsel -b -oxsel -b -o 向剪贴板中追加数据: xsel -b -a 覆盖剪贴板中的数据: xsel -b -i ...

  9. arcgis for android 无法加载本地jpg影像解决办法

    因为jpg影像没有生成金子塔文件*.rrd 一个完整的JPG影像必须包括如下文件: K-50-96-(16).aux  辅助文件K-50-96-(16).jgw  坐标信息K-50-96-(16).j ...

  10. javascript对象之 selectionStart selectionEnd

    <script> function inserttag(){ var text=document.getElementById('con'); text.focus(); var star ...