题目大意:在一个正方形的迷宫里有一些交错墙,墙的两端都在迷宫的边缘墙上面,现在得知迷宫的某个位置有一个宝藏,所以需要砸开墙来获取宝藏(只能砸一段墙的中点),问最少要砸开几面墙。
 
分析:这个题意刚开始理解错了,以为只能砸整面墙的中点,而实际上使一段墙的中点,也就是两个交点之间的墙,这样问题就变得比较容易了,中点的意义也就不存在了,因为所有的墙都是连接的边缘,所以如果从起点到终点连线有这堵墙,那么这堵墙一定无法绕过去,所以枚举所有的边缘点到终点有几面墙即可,注意不管怎样,边缘墙一定是要砸的。
 
代码如下:
===========================================================================================================================
#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. 生产者与消费者(二)---await与 signal

    前面阐述了实现生产者与消费者问题的一种方式:wait() / notify()方法,本文继续阐述多线程的经典问题---生产者与消费者的第二种方式:await() / signal()方法. await ...

  2. [LeetCode OJ] Sort Colors

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  3. 实现基于文件存储的Session类

    自主实现Session功能的类,基于文件方式存储Session数据,测试基本通过,还比较好玩,实际应用没有意义,只不过是学习Session是如何实现的. 一般基于文件存储Session数据效率不是很高 ...

  4. "The request sent by the client was syntactically incorrect ()"问题定位及解决:

    Spring MVC "The request sent by the client was syntactically incorrect ()"解决办法: 把spring日志级 ...

  5. CentOS6.5使用本地光盘做yum源 (参考:http://www.jb51.net/os/RedHat/43343.html)

    一.使用光盘做yum源安装软件 mkdir /media/CentOS  #新建CentOS挂载目录 mount -t auto /dev/cdrom /media/CentOS #挂载CentOS光 ...

  6. Ubuntu 下 安装QQ 截图工具

    1.由于ubuntu下是没有dll动态链接库的,所以需要安装一个软件wine,有这个东西之后,以后在ubuntu下就可以运行exe文件了.(wine是一款优秀的Linux系统平台下的模拟器软件,用来将 ...

  7. Model Thinking1

    Why Model Reason # 1: Intelligent Citizen of the World Reason # 2: Clearer Thinker Reason # 3: Under ...

  8. 初级SQL开发汇总指南

    汇总部分内容来自网络(作者  :zhtbs),比较基础的东西,能够了解比较基础的一些东西. Select语句概要 数据库中数据的提取(查询)使用select 语法,主要有以下几点作用 l  提取的数据 ...

  9. 十大响应式Web设计框架

    http://www.csdn.net/article/2014-05-13/2819739-responsive-frameworks-for-web-design 对于设计师而言,网站设计中的任意 ...

  10. js共享onload事件

    问题:通过js进行事件绑定,必须在HTML文档加载完成后再执行js脚本,否则可能因DOM不完整导致无法完成预计的效果,但对于不同的需求如何选用最佳的实现方式呢,这里做了整理,可以做参考. 一.对于小型 ...