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的时候 ...
随机推荐
- 杂项:MIS(管理信息系统)
ylbtech-杂项:MIS(管理信息系统) 管理信息系统(Management Information System,简称MIS)是一个以人为主导,利用计算机硬件.软件.网络通信设备以及其他办公设备 ...
- Java中jspf文件的作用
转自:https://blog.csdn.net/xzmeasy/article/details/75103431 为什么要用jspf文件 写jsp页面时,是不是:css和js引用特别多,而且有些页面 ...
- sql小计合计
转自:http://www.jb51.net/article/18860.htm 这里介绍sql server2005里面的一个使用实例: CREATE TABLE tb(province nvarc ...
- Arbitrage(floyd)
http://poj.org/problem?id=2240 #include <stdio.h> #include <string.h> <<; ][]; ][] ...
- layui富文本编译器后台获取图片路径
@RequestMapping("add") public ModelAndView add(News news){ ModelAndView mav = ne ...
- 2015 多校赛 第五场 1010 (hdu 5352)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5352 看题看得心好累. 题目大意: 给出 n 个点,依次执行 m 次操作:输入“1 x”时,表示将与 ...
- python 进程理论基础
背景知识 顾名思义,进程即一个软件正在进行的过程.进程是对正在运行的程序的一个抽象 进程的概念起源于操作系统,是操作系统的最核心的概念,也是操作系统提供的最古老的也是最重要的抽象概念之一.操作系统的其 ...
- 跳出双重for循环的案例__________跳出了,则不再执行标签ok下的for循环代码
ok: for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { System.out.print("*" ...
- NSLayoutConstraints加动画来改变约束
// // ViewController.m // NSLayoutAnimationDemo // // Created by ebaotong on 15/7/22. // Copyright ( ...
- 安卓学习之学生签到APP(一)
一.学生定位签到页面 具体实现步骤: 1.1 高德地图申请key 1.创建新应用 进入高德地图api控制台,创建一个新应用.如果您之前已经创建过应用,可直接跳过这个步骤. 2.添加新Key 在创建的应 ...