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

    UICollectionView 和 UICollectionViewController 类是iOS6 新引进的API,用于展示集合视图,布局更加灵活,可实现多列布局,用法类似于UITableVie ...

  2. 关于NSNull和nil

    在做接口数据的json解析字典的时候,一般会进行非空判断,比如一个字符串: if(str!=nil){ //do something double data=[str doubleValue]; } ...

  3. C# 绘制窗体客户非客户区要用WM_PAINT和WM_NCPAINT

    窗体分为两部分:客户区(Client area)和非客户区(Non-Client area) WM_PAINT消息.OnPaint()方法.GetDC()API函数都是处理窗体客户区绘制的   而标题 ...

  4. js获取时间加多山天和时间戳转换成日期

    function huoqu(){    var data = $("#data").val();//获取的时间    var day = $('#day').val();//往后 ...

  5. python核心编程2第二章课后练习

    2-1 变量, print 和字符串格式化运算符.启动交互式解释器.给一些变量赋值(字符串,数值等等)并通过输入变量名显示它们的值.再用 print 语句做同样的事.这二者有何区别? 也尝试着使用字符 ...

  6. 把一个string串的所有小写字母转成大写字母的例子来看看看全局函数的使用

    今天写了一个小例子,把字符串里面的所有小写字母全部转换成大写字母http://blog.csdn.net/yasaken/article/details/7303903 1 #include &quo ...

  7. 编译u-boot命令和u-boot常用命令

    一.编译u-boot命令 1.配置开发板 #make TQ2440_config 2.编译 #make all 3.交叉编译器是crosstools_3.4.5_softfloat” 使用4.3.3版 ...

  8. GMM+Kalman Filter+Blob 目标跟踪

    转 http://www.cnblogs.com/YangQiaoblog/p/5462453.html ==========图片版================================== ...

  9. Seven Steps to Success Machine Learning in Practice

    Seven Steps to Success Machine Learning in Practice Project failures in IT are all too common. The r ...

  10. Android 正则表达式匹配汉字中文

    关于中文的正则表达式, 应该是^[\\u4E00-\\u9FFF]+$, 和论坛里常被人提起的^[\\u4E00-\\u9FA5]+$很接近需要注意的是论坛里说的^[\\u4E00-\\u9FA5]+ ...