The Doors - POJ 1556 (线段相交)
题目大意:有一个房间(左上角(0,10),右下角(10,0)),然后房间里有N面墙,每面墙上都有两个门,求出来从初始点(0,5),到达终点(10,5)的最短距离。
#include<math.h>
#include<algorithm>
#include<stdio.h>
using namespace std; const int MAXN = ;
const double oo = 1e9+;
const double EPS = 1e-; struct point
{
double x, y, len;
point(double x=, double y=, double len=):x(x),y(y),len(len){}
point operator - (const point &t) const{
return point(x-t.x, y-t.y);
}
int operator *(const point &t) const{
double c = x*t.y - y*t.x;
if(c > EPS)return ;
if(fabs(c)<EPS)return ;
return -;
}
};
struct Wall
{
point A, B;
Wall(point A=, point B=):A(A), B(B){}
}; bool CanLine(point a, point b, Wall w[], int N)
{
for(int i=; i<N; i++)
{
if( w[i].A.x < b.x || w[i].A.x > a.x )
continue;
int t = (a-b)*(w[i].A-b) + (a-b)*(w[i].B-b); if(t == )
return false;
} return true;
} int main()
{
int M; while(scanf("%d", &M) != EOF && M != -)
{
int i, j, nw=, np=;
double x, y[];
Wall w[MAXN]; point p[MAXN]; p[] = point(, , );
while(M--)
{
scanf("%lf%lf%lf%lf%lf", &x, &y[], &y[], &y[], &y[]); p[np++] = point(x, y[], oo), p[np++] = point(x, y[], oo);
p[np++] = point(x, y[], oo), p[np++] = point(x, y[], oo);
w[nw++] = Wall(point(x, -), point(x, y[]));
w[nw++] = Wall(point(x, y[]), point(x, y[]));
w[nw++] = Wall(point(x, y[]), point(x, ));
}
p[np++] = point(, , oo); for(i=; i<np; i++)
for(j=; j<i; j++)
{
point t = p[i] - p[j];
t.len = sqrt(t.x*t.x+t.y*t.y); if(p[i].len > t.len + p[j].len && CanLine(p[i], p[j], w, nw) == true)
p[i].len = t.len + p[j].len;
} printf("%.2f\n", p[np-].len);
} return ;
}
The Doors - POJ 1556 (线段相交)的更多相关文章
- poj 1066 线段相交
链接:http://poj.org/problem?id=1066 Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- poj 1269 线段相交/平行
模板题 注意原题中说的线段其实要当成没有端点的直线.被坑了= = #include <cmath> #include <cstdio> #include <iostrea ...
- poj 2653 线段相交
题意:一堆线段依次放在桌子上,上面的线段会压住下面的线段,求找出没被压住的线段. sol:从下向上找,如果发现上面的线段与下面的相交,说明被压住了.break掉 其实这是个n^2的算法,但是题目已经说 ...
- poj 2653 线段相交裸题(解题报告)
#include<stdio.h> #include<math.h> const double eps=1e-8; int n; int cmp(double x) { if( ...
- poj 1410 线段相交判断
http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Pipe - POJ 1039(线段相交交点)
题目大意:有一个不反光并且不透光的管道,现在有一束光线从最左端进入,问能达到的最右端是多少,输出x坐标. 分析:刚开始做是直接枚举两个点然后和管道进行相交查询,不过这样做需要考虑的太多,细节不容易 ...
- Pick-up sticks - POJ 2653 (线段相交)
题目大意:有一个木棒,按照顺序摆放,求出去上面没有被别的木棍压着的木棍..... 分析:可以维护一个队列,如果木棍没有被压着就入队列,如果判断被压着,就让那个压着的出队列,最后把这个木棍放进队列, ...
- POJ 2074 | 线段相交
#include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #defi ...
- POJ 1556 The Doors 线段交 dijkstra
LINK 题意:在$10*10$的几何平面内,给出n条垂直x轴的线,且在线上开了两个口,起点为$(0, 5)$,终点为$(10, 5)$,问起点到终点不与其他线段相交的情况下的最小距离. 思路:将每个 ...
随机推荐
- 关于 const 成员函数
成员函数如果是const意味着什么? 有两个流行概念:物理常量性和逻辑常量性. C++对常量性的定义采用的是物理常量性概念,即const 成员函数不可以更改对象内任何non-static成员变量.例如 ...
- 去掉Visual Studio 编辑器里中文注释的红色波浪线 转载
我们通常用visual studio进行开发的时候,我们通常会用到一款比较流行比较方便的插件,那就是Visual Assist X,它可以增强Microsoft开发环境下的编辑能力,支持C/C++,C ...
- (转)Android开发:性能最佳实践-管理应用内存
翻自:http://developer.android.com/training/articles/memory.html 在任何软件开发环境中,RAM都是宝贵的资源,但在移动操作系统中更加珍贵.尽管 ...
- Burp Suite Walkthrough
Burp Suite is one of the best tools available for web application testing. Its wide variety of featu ...
- HDU 5491 The Next
Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...
- 按钮效果 css
<!doctype html><html lang="en"><head> <meta charset="UTF-8" ...
- linux上配置subversion服务器端安装配置并使用svn,windows本地检出,设置同步更新服务器的钩子
参考http://my.oschina.net/junn/blog/164041 http://songxj.blog.51cto.com/620981/396113 http://5iwww.blo ...
- Android中基于Socket的网络通信
1. Socket介绍 2. ServerSocket的建立与使用 3. 使用ServerSocket建立聊天服务器-1 4. 使用ServerSocket建立聊天服务器-2 5. 在Android中 ...
- 开启g++ 编辑器 c++11特性
以前都是在windows下用vs和cvi写C和C++代码,最近练习Linux下的使用. 编译的时候使用C++11的新特性比如auto 和 iteration特性都报不支持,后来在知乎看到答案需要在编译 ...
- button 垂直分布
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];//button的类型 button.frame = CGRectMak ...