http://poj.org/problem?id=1066

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#define maxn 500000
using namespace std; const double eps=1e-;
const int inf=<<;
int t1,t2,t3,t4,t5,c; int cmp(double x)
{
if(fabs(x)<eps) return ;
if(x>) return ;
return -;
} struct point
{
double x,y;
point() {}
point(double a,double b):x(a),y(b) {}
friend point operator -(const point &a,const point &b)
{
return point(a.x-b.x,a.y-b.y);
}
friend point operator *(const point &a,const double &b)
{
return point(a.x*b,a.y*b);
}
friend point operator /(const point &a,const double &b)
{
return point(a.x/b,a.y/b);
}
} p[maxn];
point m[][]; int cmp1(const point &a,const point &b)
{
return a.x<b.x;
} int cmp2(const point &a,const point &b)
{
return a.y<b.y;
} struct line
{
point a,b;
line() {}
line(point x,point y):a(x),b(y) {};
} ll[maxn]; double det(const point &a,const point &b)
{
return a.x*b.y-a.y*b.x;
} bool segment(point a1,point a2,point b1,point b2)
{
double c1=det(a2-a1,b1-a1),c2=det(a2-a1,b2-a1);
double c3=det(b2-b1,a1-b1),c4=det(b2-b1,a2-b1);
return cmp(c1)*cmp(c2)<&&cmp(c3)*cmp(c4)<;
} void make(double x,double y)
{
if(y==)
{
m[][t1].x=x;
m[][t1++].y=y;
}
else if(y==)
{
m[][t2].x=x;
m[][t2++].y=y;
}
else if(x==)
{
m[][t3].x=x;
m[][t3++].y=y;
}
else if(x==)
{
m[][t4].x=x;
m[][t4++].y=y;
}
} void inti()
{
for(int i=; i<=t1; i++)
{
p[c].x=(m[][i].x+m[][i-].x)/;
p[c++].y=;
}
for(int i=; i<=t3; i++)
{
p[c].y=(m[][i].y+m[][i-].y)/;
p[c++].x=;
}
for(int i=; i<=t2; i++)
{
p[c].x=(m[][i].x+m[][i-].x)/;
p[c++].y=;
}
for(int i=; i<=t4; i++)
{
p[c].y=(m[][i].y+m[][i-].y)/;
p[c++].x=;
}
}
int main()
{
int T;
while(scanf("%d",&T)!=EOF)
{
int n=T;
double x1,y1,x2,y2;
t1=,t2=,t3=,t4=,t5=;
c=;
while(T--)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
make(x1,y1);
make(x2,y2);
point st(x1,y1);
point st1(x2,y2);
ll[t5].a=st;
ll[t5++].b=st1;
}
m[][].x=;
m[][].y=;
m[][t1].x=;
m[][t1].y=;
m[][t3].x=;
m[][t3].y=;
m[][].x=;
m[][].y=;
m[][].x=;
m[][].y=;
m[][t2].x=;
m[][t2].y=;
m[][].x=;
m[][].y=;
m[][t4].x=;
m[][t4].y=;
sort(m[],m[]+t1+,cmp1);
sort(m[],m[]+t2+,cmp1);
sort(m[],m[]+t3+,cmp2);
sort(m[],m[]+t4+,cmp2);
inti();
point pp,p1;
scanf("%lf%lf",&pp.x,&pp.y);
int ans=inf;
for(int i=; i<c; i++)
{
line l1(p[i],pp);
int ans1=;
for(int j=; j<t5; j++)
{
if(segment(l1.a,l1.b,ll[j].a,ll[j].b)) ans1++;
}
ans=min(ans,ans1);
}
if(n==)
{
ans=;
}
printf("Number of doors = %d\n",ans+);
}
return ;
}

poj 1066 Treasure Hunt的更多相关文章

  1. poj 1066 Treasure Hunt (Geometry + BFS)

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

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

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

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

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

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

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

  5. POJ 1066 Treasure Hunt [想法题]

    题目链接: http://poj.org/problem?id=1066 --------------------------------------------------------------- ...

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

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

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

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

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

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

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

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

随机推荐

  1. 【.NET调用Python脚本】C#调用python requests类库报错 'module' object has no attribute '_getframe' - IronPython 2.7

    最近在开发微信公众号,有一个自定义消息回复的需求 比如用户:麻烦帮我查询一下北京的天气? 系统回复:北京天气,晴,-℃... 这时候需要根据关键字[北京][天气],分词匹配需要执行的操作,然后去调用天 ...

  2. [Angular 2] ng-model and ng-for with Select and Option elements

    You can use Select and Option elements in combination with ng-for and ng-model to create mini-forms ...

  3. python-列表、字典、元组的员工信息处理接口(第二篇(五):基于列表、字典和元组的员工信息处理接口)

    Python之旅]第二篇(五):基于列表.字典和元组的员工信息处理接口 python 列表 字典 元组 员工信息处理接口 摘要: 1.基本需求     编写一个查询员工信息表的程序,实现如下功能: ( ...

  4. C#中接口和抽象类

    1抽象类 (1) 抽象方法只作声明,而不包含实现,可以看成是没有实现体的虚方法 (2) 抽象类不能被实例化 (3) 抽象类可以但不是必须有抽象属性和抽象方法,但是一旦有了抽象方法,就一定要把这个类声明 ...

  5. HDU5319

    题意:给一个矩形染色,顺笔表示红色,逆笔表示蓝色(既一捺和一丿),交叉表示绿色,然后给你一个图,问你用多少笔能画出这个图来. 思路:对这个图直接模拟即可,如果点i,j坐标为红色,那么判断上一个路径点是 ...

  6. Linq101-Aggregate

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Aggrega ...

  7. Request 获取Url

    1.获取页面,HttpContext.Current.Request也是Request //获取当前页面url string myurl = HttpContext.Current.Request.U ...

  8. c#将Excel数据导入到数据库的实现代码(OleDb)

    sing System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web ...

  9. linux 'more' command.

    more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会 ...

  10. 【USACO 1.3.2】修理牛棚

    [描述] 在一个夜黑风高,下着暴风雨的夜晚,farmer John的牛棚的屋顶.门被吹飞了. 好在许多牛正在度假,所以牛棚没有住满. 牛棚一个紧挨着另一个被排成一行,牛就住在里面过夜. 有些牛棚里有牛 ...