Treasure Hunt - POJ 1066(线段相交判断)
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std; const int MAXN = 1e3+;
const int oo = 1e9+;
const double EPS = 1e-; struct point
{
double x, y;
point(double x=, double y=):x(x), y(y){}
point operator - (const point &t) const{
return point(x-t.x, y-t.y);
}
int operator *(const point &t) const{
double ans = x * t.y - y * t.x; if(ans > EPS)return ;
if(fabs(ans) < EPS)return ;
return -;
}
bool operator == (const point &t) const{
return fabs(x-t.x)<EPS && fabs(y-t.y)<EPS;
}
};
struct segment
{
point A, B;
segment(point A=, point B=):A(A), B(B){}
bool inter(const segment &t) const{
return (A-B)*(t.A-B) + (A-B)*(t.B-B) == ;
}
};
int Find(segment a, segment sg[], int N)
{
int sum = ; for(int i=; i<N; i++)
{
if(a.inter(sg[i]) && sg[i].inter(a))
sum++;
} return sum;
} int main()
{
int N; while(scanf("%d", &N) != EOF)
{
int k=, Min = oo;
segment sg[MAXN];
point p[MAXN], End, A, B; for(int i=; i<N; i++)
{
scanf("%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y);
p[k++] = A, p[k++] = B;
sg[i] = segment(A, B);
}
scanf("%lf%lf", &End.x, &End.y); for(int i=; i<k; i++)
{
if(p[i] == End)
continue;
Min = min(Min, Find(segment(End, p[i]), sg, N)+);
} if(Min == oo)Min = ; printf("Number of doors = %d\n", Min);
} return ;
}
Treasure Hunt - POJ 1066(线段相交判断)的更多相关文章
- poj 1066 线段相交
链接:http://poj.org/problem?id=1066 Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- POJ 1066 Treasure Hunt --几何,线段相交
题意: 正方形的房子,给一些墙,墙在区域内是封闭的,给你人的坐标,每穿过一道墙需要一把钥匙,问走出正方形需要多少把钥匙. 解法: 因为墙是封闭的,所以绕路也不会减少通过的墙的个数,还不如不绕路走直线, ...
- poj 1410 线段相交判断
http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- POJ 1066 Treasure Hunt(线段相交判断)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4797 Accepted: 1998 Des ...
- POJ 3449 Geometric Shapes(判断几个不同图形的相交,线段相交判断)
Geometric Shapes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1243 Accepted: 524 D ...
- POJ 1039 Pipe(直线和线段相交判断,求交点)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8280 Accepted: 2483 Description ...
- POJ 3304 Segments (直线和线段相交判断)
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7739 Accepted: 2316 Descript ...
- poj 1269 线段相交/平行
模板题 注意原题中说的线段其实要当成没有端点的直线.被坑了= = #include <cmath> #include <cstdio> #include <iostrea ...
- poj 2653 线段相交
题意:一堆线段依次放在桌子上,上面的线段会压住下面的线段,求找出没被压住的线段. sol:从下向上找,如果发现上面的线段与下面的相交,说明被压住了.break掉 其实这是个n^2的算法,但是题目已经说 ...
随机推荐
- Jquery插件之信息弹出框showInfoDialog(成功、错误、警告、通知)
一.信息种类说明: 1.1.操作成功信息 1.2.错误信息 1.3.警告信息 1.4.通知信息 二.使用说明 <!DOCTYPE html PUBLIC "-//W3C//DTD HT ...
- java学习之反射机制
java语言区别于C,C++等准静态语言的最大特点就是java的反射机制.静态语言的最直接定义就是不能在运行时改变程序结构或变量的类型.按照这样的定义,python,ruby是动态语言,C,C++,J ...
- html本地存储尝试
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 滑动开关效果 css3滑动开关】纯CSS3代码实现滑动开关效果-css3滑动效果-css3左右滑动
今天看到一篇有关 css3事件的博文,一时兴起便整理下相关的资料. 点击按钮,可以实现开关的滑动效果. 今天看到一篇有关 css3事件的博文,一时兴起便整理下相关的资料. 点击按钮,可以实现开关的滑动 ...
- 移动端触摸滑动插件Swiper
移动端触摸滑动插件Swiper 04/02/2015 一.了解Swiper 目前移动端项目一般都需要具有触屏焦点图的效果,如果你也需要实现这一功能的话,Swiper是一个不错的选择. 1.他不需要加载 ...
- jquery 学习日记之选择器
看完Jquery选择器的教程视频后,对jquery的选择器有一定的认识和了解,现整理一下知识: 一.jquery基本选择器,这类比较简单,一笔带过. #id 选择器,是选择 匹配id值中的第一个元素 ...
- Colletion View 简单的备忘
UIColletionView 这篇只是做UIColletionView的常用属性.代理方法和数据源方法的备忘,之后做一些自定义布局,增加删除动画等. UIColletionViewFlowLayou ...
- JSP面试题及答案
更新时间:2015-04-07 来源:网络 投诉删除 [看准网(Kanzhun.com)]JSP面试题频道小编搜集的范文“JSP面试题及答案”,供大家阅读参考,查看更多 ...
- Java: 实现顺序表和单链表的快速排序
快速排序 快速排序原理 快速排序(Quick Sort)的基本思想是,通过一趟排序将待排记录分割成独立的两部分,其中一部分记录的关键字均比另一部分记录的关键字小,则可对这两部分记录继续进行排序,以达到 ...
- Learning LexRank——Graph-based Centrality as Salience in Text Summarization(一)
(1)What is Sentence Centrality and Centroid-based Summarization ? Extractive summarization works by ...