题意: 正方形的房子,给一些墙,墙在区域内是封闭的,给你人的坐标,每穿过一道墙需要一把钥匙,问走出正方形需要多少把钥匙。

解法: 因为墙是封闭的,所以绕路也不会减少通过的墙的个数,还不如不绕路走直线,所以枚举角度,得出直线,求出与正方形内的所有墙交点最少的值,最后加1(正方形边界)。

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <algorithm>
  7. #define Mod 1000000007
  8. #define pi acos(-1.0)
  9. #define eps 1e-8
  10. using namespace std;
  11. #define N 100017
  12.  
  13. struct Point{
  14. double x,y;
  15. Point(double x=, double y=):x(x),y(y) {}
  16. void input() { scanf("%lf%lf",&x,&y); }
  17. };
  18. typedef Point Vector;
  19. struct Circle{
  20. Point c;
  21. double r;
  22. Circle(){}
  23. Circle(Point c,double r):c(c),r(r) {}
  24. Point point(double a) { return Point(c.x + cos(a)*r, c.y + sin(a)*r); }
  25. void input() { scanf("%lf%lf%lf",&c.x,&c.y,&r); }
  26. };
  27. struct Line{
  28. Point p;
  29. Vector v;
  30. double ang;
  31. Line(){}
  32. Line(Point p, Vector v):p(p),v(v) { ang = atan2(v.y,v.x); }
  33. Point point(double t) { return Point(p.x + t*v.x, p.y + t*v.y); }
  34. bool operator < (const Line &L)const { return ang < L.ang; }
  35. };
  36. int dcmp(double x) {
  37. if(x < -eps) return -;
  38. if(x > eps) return ;
  39. return ;
  40. }
  41. template <class T> T sqr(T x) { return x * x;}
  42. Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
  43. Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); }
  44. Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); }
  45. Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); }
  46. bool operator < (const Point& a, const Point& b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
  47. bool operator >= (const Point& a, const Point& b) { return a.x >= b.x && a.y >= b.y; }
  48. bool operator <= (const Point& a, const Point& b) { return a.x <= b.x && a.y <= b.y; }
  49. bool operator == (const Point& a, const Point& b) { return dcmp(a.x-b.x) == && dcmp(a.y-b.y) == ; }
  50. double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }
  51. double Length(Vector A) { return sqrt(Dot(A, A)); }
  52. double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); }
  53. double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
  54. Vector VectorUnit(Vector x){ return x / Length(x);}
  55. Vector Normal(Vector x) { return Point(-x.y, x.x) / Length(x);}
  56. double angle(Vector v) { return atan2(v.y, v.x); }
  57.  
  58. bool SegmentIntersection(Point A,Point B,Point C,Point D) {
  59. if(dcmp(Cross(C-A,B-A)*Cross(D-A,B-A)) <= && dcmp(Cross(A-C,D-C)*Cross(B-C,D-C)) <= ) return true;
  60. return false;
  61. }
  62. //data segment
  63. struct Seg{
  64. Point P[];
  65. }seg[];
  66. //data ends
  67.  
  68. int main()
  69. {
  70. int n,m,i,j;
  71. scanf("%d",&n);
  72. for(i=;i<=n;i++)
  73. seg[i].P[].input(), seg[i].P[].input();
  74. Point C,D;
  75. C.input();
  76. int Mini = Mod;
  77. double delta = *pi*0.001;
  78. for(i=;i<=;i++)
  79. {
  80. double ang = delta*i;
  81. D.x = 10000.0*cos(ang) + C.x;
  82. D.y = 10000.0*sin(ang) + C.y;
  83. int cnt = ;
  84. for(j=;j<=n;j++)
  85. if(SegmentIntersection(seg[j].P[],seg[j].P[],C,D))
  86. cnt++;
  87. Mini = min(Mini,cnt);
  88. }
  89. printf("Number of doors = %d\n",Mini+);
  90. return ;
  91. }

POJ 1066 Treasure Hunt --几何,线段相交的更多相关文章

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

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

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

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

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

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

  4. poj 1066 Treasure Hunt (Geometry + BFS)

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. log4j.xml 配置参数属性level使用心得

    jdbc.sqlonly        只显示执行的sql语句.info级才可以显示,debug增加显示java源代码位置. jdbc.sqltiming    显示执行的sql语句以及语句执行时间, ...

  2. swift学习笔记之-自动引用计数

    //自动引用计数 import UIKit /*自动引用计数(Automatic Reference Counting) 防止循环强引用 Swift 使用自动引用计数(ARC)机制来跟踪和管理你的应用 ...

  3. javascript --- 设计模式之单体模式(二)

    在JavaScript里,实现单例的方式有很多种,其中最简单的一个方式是使用对象字面量的方法,其字面量里可以包含大量的属性和方法: var her = { property1: 'someing', ...

  4. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q81-Q84)

    Question 81You need to create a Web Part that creates a copy of the out-of-the-box Contribute permis ...

  5. TCP/IP协议握手过程详解

    1,建立连接 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接,如图1所示. (1)第一次握手:建立连接时,客户端A发送SYN包(SYN=j)到服务器B,并进入SYN_SE ...

  6. android:descendantFocusability=”blocksDescendants”的用法

    android:descendantFocusability用法简析 开发中很常见的一个问题,项目中的listview不仅仅是简单的文字,常常需要自己定义listview,自己的Adapter去继承B ...

  7. AccessRandomFile多线程下载文件

    写一个工具类 package com.pb.thread.demo; import java.io.File; import java.io.FileNotFoundException; import ...

  8. 网络开始---多线程---NSThread-01-基本使用(了解)(二)

    #import "HMViewController.h" @interface HMViewController () @end @implementation HMViewCon ...

  9. IOS开发之实现App消息推送(最新)

    好久没有写过博客啦,今天就由本菜鸟给大家做一个简单的IOSApp消息推送教程吧!一切从0开始,包括XCode6, IOS8, 以及苹果开发者中心最新如何注册应用,申请证书以及下载配置概要文件,相信很多 ...

  10. iOS 正则表达式判断邮箱、身份证..是否正确

    //邮箱 + (BOOL) validateEmail:(NSString *)email { NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Z ...