POJ 1066
由于到达点时不能绕墙,因为这是无意义的,所以,两点间的最小墙依然是按照直线所穿过的墙计算。
#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的更多相关文章
- 线段相交 poj 1066
// 线段相交 poj 1066 // 思路:直接枚举每个端点和终点连成线段,判断和剩下的线段相交个数 // #include <bits/stdc++.h> #include <i ...
- poj 1066 线段相交
链接:http://poj.org/problem?id=1066 Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- poj 1066 Treasure Hunt
http://poj.org/problem?id=1066 #include <cstdio> #include <cstring> #include <cmath&g ...
- POJ 1066 - Treasure Hunt - [枚举+判断线段相交]
题目链接:http://poj.org/problem?id=1066 Time Limit: 1000MS Memory Limit: 10000K Description Archeologist ...
- POJ 1066 Treasure Hunt [想法题]
题目链接: http://poj.org/problem?id=1066 --------------------------------------------------------------- ...
- poj 1066 Treasure Hunt (Geometry + BFS)
1066 -- Treasure Hunt 题意是,在一个金字塔中有一个宝藏,金字塔里面有很多的墙,要穿过墙壁才能进入到宝藏所在的地方.可是因为某些原因,只能在两个墙壁的交点连线的中点穿过墙壁.问最少 ...
- POJ 1066 Treasure Hunt (线段相交)
题意:给你一个100*100的正方形,再给你n条线(墙),保证线段一定在正方形内且端点在正方形边界(外墙),最后给你一个正方形内的点(保证不再墙上) 告诉你墙之间(包括外墙)围成了一些小房间,在小房间 ...
- POJ 1066 Treasure Hunt【线段相交】
思路:枚举四边墙的门的中点,与终点连成一条线段,判断与其相交的线段的个数.最小的加一即为答案. 我是傻逼,一个数组越界调了两个小时. #include<stdio.h> #include& ...
- POJ 1066 Treasure Hunt --几何,线段相交
题意: 正方形的房子,给一些墙,墙在区域内是封闭的,给你人的坐标,每穿过一道墙需要一把钥匙,问走出正方形需要多少把钥匙. 解法: 因为墙是封闭的,所以绕路也不会减少通过的墙的个数,还不如不绕路走直线, ...
- 简单几何(线段相交) POJ 1066 Treasure Hunt
题目传送门 题意:从四面任意点出发,有若干障碍门,问最少要轰掉几扇门才能到达终点 分析:枚举入口点,也就是线段的两个端点,然后选取与其他线段相交点数最少的 + 1就是答案.特判一下n == 0的时候 ...
随机推荐
- python之路——常用模块
阅读目录 认识模块 什么是模块 模块的导入和使用 常用模块一 collections模块 时间模块 random模块 os模块 sys模块 序列化模块 re模块 常用模块二 hashlib模块 con ...
- C#利用ICSharpCode将远程文件打包并下载
应用于ASP.NET MVC中 方法主体代码: public void GetFilesByOrder(string Order_ID, string IntNumber) { MemoryStrea ...
- Oracle 数据导入导出(imp/exp)
环境:windows下,oracle11g 1.启动oracle服务 net start OracleDBConsoleorclnet start OracleOraDb11g_home1TNSLis ...
- 这是一个无效的原路径/url
当我们在SourceTree上新建一个“从URL克隆”的远程项目时,在确认“URL”无误的前提下依然报红色字体“这是一个无效的原路径/URL”错误,我们只需要快捷键“Command + ,”打开Sou ...
- React+Dva
Reducer reducer 是一个函数,接受 state 和 action,返回老的或新的 state .即:(state, action) => state Effect app.mode ...
- Android几种常见的多渠道(批量)打包方式介绍
多渠道打包,主要是为了统计不同的渠道上包的下载数量,渠道越多,我们需要打的包数量越多,这个时候,我们没法去使用单纯的手动打包去一个一个的生成不同的渠道包,我们需要更高效的打包方式. 声明渠道方式一: ...
- ★Java语法(六)——————————分支语句
1. if 语句 格式用法: if(布尔表达式) { 语句: } 2. if……else 语句 格式用法: if(表达式) { 语句1: } else { 语句2: } 3.if……else i ...
- 【PLSQL】游标
Oracle中的SQL在执行时需要分配一块内存区域,这块内存区域叫做上下文区. 上下文区中记录了SQL语句的处理信息,这些信息包括:查询返回的数据行.查询所处理的数据的行号.指向共享池中的已分析的SQ ...
- windows下安装Python-Whl文件
原文链接:http://blog.sciencenet.cn/home.php?mod=space&uid=1181151&do=blog&id=865515 Note1. 整 ...
- Match 基因匹配 题解(From luoguBlog)
N<=20000!N2的LCS要原地爆炸. 去您妈的优化考场上有分就行TLE60真香嘿嘿嘿 然而这显然是个板子只不过像我这样见识短浅的蒟蒻不知道罢了 正解: 某大佬的博客 转化为lis后二分 复 ...