由于到达点时不能绕墙,因为这是无意义的,所以,两点间的最小墙依然是按照直线所穿过的墙计算。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const double eps=0.000000001;
struct point{
double x,y;
}Point[100],des;
struct edge{
point start,end;
}Edge[100],Tmp; int ne,np; double multi(point p1,point p2, point p0){
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
} bool cross(edge v1, edge v2){
if(max(v1.start.x,v1.end.x)>=min(v2.start.x,v2.end.x)&&
max(v2.start.x,v2.end.x)>=min(v1.start.x,v1.end.x)&&
max(v1.start.y,v1.end.y)>=min(v2.start.y,v2.end.y)&&
max(v2.start.y,v2.end.y)>=min(v1.start.y,v1.end.y)&&
multi(v2.start,v1.end,v1.start)*multi(v1.end,v2.end,v1.start)>eps&&
multi(v1.start,v2.end,v2.start)*multi(v2.end,v1.end,v2.start)>eps)
return true;
return false;
} int main(){
while(scanf("%d",&ne)!=EOF){
np=0;
for(int i=0;i<ne;i++){
scanf("%lf%lf",&Point[np].x,&Point[np].y);
np++;
scanf("%lf%lf",&Point[np].x,&Point[np].y);
np++;
Edge[i].start=Point[np-2]; Edge[i].end=Point[np-1];
}
Point[np].x=0; Point[np].y=0;
np++;
Point[np].x=0; Point[np].y=100;
np++;
Point[np].x=100; Point[np].y=0;
np++;
Point[np].x=100; Point[np].y=100;
np++;
scanf("%lf%lf",&des.x,&des.y);
int ans=1000,tmp;
for(int i=0;i<np;i++){
Tmp.start=des; Tmp.end=Point[i]; tmp=0;
for(int i=0;i<ne;i++){
if(cross(Tmp,Edge[i]))
tmp++;
}
ans=min(ans,tmp);
}
printf("Number of doors = %d\n",ans+1);
}
}

  

POJ 1066的更多相关文章

  1. 线段相交 poj 1066

    // 线段相交 poj 1066 // 思路:直接枚举每个端点和终点连成线段,判断和剩下的线段相交个数 // #include <bits/stdc++.h> #include <i ...

  2. poj 1066 线段相交

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

  3. poj 1066 Treasure Hunt

    http://poj.org/problem?id=1066 #include <cstdio> #include <cstring> #include <cmath&g ...

  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 (Geometry + BFS)

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

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

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

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

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

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

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

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

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

随机推荐

  1. 分享的js代码,从w3c上拓下来的

    <!DOCTYPE html><html><head> <title></title> <script>window._bd_s ...

  2. [Apple开发者帐户帮助]二、管理你的团队(4)离开一个团队

    您可以随时离开组织的开发团队.但是,帐户持有人有法律责任,只能在指定另一个团队成员作为帐户持有人后离开团队. 如果您是Apple Developer Program中的团队成员,则可以将团队留在App ...

  3. 利用poi,jxl将Excel数据导入数据库

    需求:‘需要将本地的Excel中的数据经过验证之后导入数据库,在导入数据库之前在页面上展示出来 思路:将Excel导入存到session里面 去判断有没有不合法数据  如果有阻止提交 工具类: imp ...

  4. 通过学习Date和Calendar时写的日历

    package com.etc.util; import java.util.Calendar; import java.util.Scanner; public class Calendar2 { ...

  5. 记录一个MySQL的问题

    昨天做asp.net mvc程序,用mysql.data.entity.ef6做数据连接. 程序都是正常的,但就是提交数据的时候总是提示 Specified key was too long; max ...

  6. iOS多线程——GCD篇

    什么是GCD GCD是苹果对多线程编程做的一套新的抽象基于C语言层的API,结合Block简化了多线程的操作,使得我们对线程操作能够更加的安全高效. 在GCD出现之前Cocoa框架提供了NSObjec ...

  7. css的选择器效率分析

    我们都知道,CSS具有叠加性(同一个元素被多条样式规则指定),继承性(后代元素会继承前辈元素的一些样式和属性)和优先级 (由于CSS的叠加性和继承性,将产生优先级,这指的是哪条样式规则会最终作用于指定 ...

  8. akka框架——异步非阻塞高并发处理框架

    akka actor, akka cluster akka是一系列框架,包括akka-actor, akka-remote, akka-cluster, akka-stream等,分别具有高并发处理模 ...

  9. Deutsch lernen (04)

    1. streng a. 严厉的,严格的 streng gegen sich selbst und gegen andere sein streng auf Ordnung halten 2. ver ...

  10. Java_Web之JSTL和EL

    今天学了JSTL和EL,替换了以前for循环,感觉代码越来越少了,十分方便.JSTL和EL密不可分. 一.什么是EL表达式? 什么是EL EL即Expression Language(表达式语言) E ...