题目大意:在一个正方形的迷宫里有一些交错墙,墙的两端都在迷宫的边缘墙上面,现在得知迷宫的某个位置有一个宝藏,所以需要砸开墙来获取宝藏(只能砸一段墙的中点),问最少要砸开几面墙。
 
分析:这个题意刚开始理解错了,以为只能砸整面墙的中点,而实际上使一段墙的中点,也就是两个交点之间的墙,这样问题就变得比较容易了,中点的意义也就不存在了,因为所有的墙都是连接的边缘,所以如果从起点到终点连线有这堵墙,那么这堵墙一定无法绕过去,所以枚举所有的边缘点到终点有几面墙即可,注意不管怎样,边缘墙一定是要砸的。
 
代码如下:
===========================================================================================================================
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std; const int MAXN = 1e3+;
const int oo = 1e9+;
const double EPS = 1e-; struct point
{
double x, y;
point(double x=, double y=):x(x), y(y){}
point operator - (const point &t) const{
return point(x-t.x, y-t.y);
}
int operator *(const point &t) const{
double ans = x * t.y - y * t.x; if(ans > EPS)return ;
if(fabs(ans) < EPS)return ;
return -;
}
bool operator == (const point &t) const{
return fabs(x-t.x)<EPS && fabs(y-t.y)<EPS;
}
};
struct segment
{
point A, B;
segment(point A=, point B=):A(A), B(B){}
bool inter(const segment &t) const{
return (A-B)*(t.A-B) + (A-B)*(t.B-B) == ;
}
};
int Find(segment a, segment sg[], int N)
{
int sum = ; for(int i=; i<N; i++)
{
if(a.inter(sg[i]) && sg[i].inter(a))
sum++;
} return sum;
} int main()
{
int N; while(scanf("%d", &N) != EOF)
{
int k=, Min = oo;
segment sg[MAXN];
point p[MAXN], End, A, B; for(int i=; i<N; i++)
{
scanf("%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y);
p[k++] = A, p[k++] = B;
sg[i] = segment(A, B);
}
scanf("%lf%lf", &End.x, &End.y); for(int i=; i<k; i++)
{
if(p[i] == End)
continue;
Min = min(Min, Find(segment(End, p[i]), sg, N)+);
} if(Min == oo)Min = ; printf("Number of doors = %d\n", Min);
} return ;
}

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

  1. poj 1066 线段相交

    链接:http://poj.org/problem?id=1066 Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  2. POJ 1066 Treasure Hunt --几何,线段相交

    题意: 正方形的房子,给一些墙,墙在区域内是封闭的,给你人的坐标,每穿过一道墙需要一把钥匙,问走出正方形需要多少把钥匙. 解法: 因为墙是封闭的,所以绕路也不会减少通过的墙的个数,还不如不绕路走直线, ...

  3. poj 1410 线段相交判断

    http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

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

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

  5. POJ 3449 Geometric Shapes(判断几个不同图形的相交,线段相交判断)

    Geometric Shapes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1243   Accepted: 524 D ...

  6. POJ 1039 Pipe(直线和线段相交判断,求交点)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8280   Accepted: 2483 Description ...

  7. POJ 3304 Segments (直线和线段相交判断)

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7739   Accepted: 2316 Descript ...

  8. poj 1269 线段相交/平行

    模板题 注意原题中说的线段其实要当成没有端点的直线.被坑了= = #include <cmath> #include <cstdio> #include <iostrea ...

  9. poj 2653 线段相交

    题意:一堆线段依次放在桌子上,上面的线段会压住下面的线段,求找出没被压住的线段. sol:从下向上找,如果发现上面的线段与下面的相交,说明被压住了.break掉 其实这是个n^2的算法,但是题目已经说 ...

随机推荐

  1. 禁用UITextField复制粘贴等方法

    要实现此功能只需创建一个继承自UITextField的子类,重写以下方法即可. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender{ ...

  2. WCF 无法生成 client

    在MVC中调用WCF 总是没有client 后来在网上查找原因,去掉Reuse type in referrenced assenbiles ,就可以生成代理代码.

  3. RecordSet .CacheSize, Properties,CurserType,PageSize

    使用 CacheSize 属性可以控制一次要从提供者那里将多少个记录检索到本地内存中.例如,如果 CacheSize 为 10,首次打开 Recordset 对象后,提供者将把前 10 个记录检索到本 ...

  4. JS-运动框架

    写这段代码,是因为之前看过某前RD写过,但在测试过程中发现有不完美的地方. 问题在于判断运动停止条件这里,对于之前停止的判断太片面,只能判断一个条件值时的情况,对于多条件时,会发现运动后的各项值并未达 ...

  5. Winbind authentication against active directory

    Winbind authentication against active directory Description This tip will describe how to configure ...

  6. 浅谈Exchange 2013开发-如何操作邮件的附件

    因为项目中客户有一个的要求,所以这个Exchange前段时间搞的我很是头疼,没接触过这个东西,但是现在看来,纸老虎一个.希望我的经验可以帮助初次接触它的人少走一些弯路! 简单介绍一下:客户要求在自己的 ...

  7. 学习Swift -- 析构过程

    析构过程 析构器只适用于类类型,当一个类的实例被释放之前,析构器会被立即调用.析构器用关键字deinit来标示,类似于构造器要用init来标示. 原理 Swift 会自动释放不再需要的实例以释放资源, ...

  8. gcd 控制线程执行顺序(供参考)

    dispatch_group_t group = dispatch_group_create(); dispatch_group_async(group, dispatch_get_global_qu ...

  9. 基于Java的Http服务器几种模式演进

    首先抛出问题: 程序1---错误版本 import java.io.IOException; import java.io.InputStream; import java.io.PrintWrite ...

  10. 数据结构练习 01-复杂度2. Maximum Subsequence Sum (25)

    Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...