题目链接:http://poj.org/problem?id=1556

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = ;
const int maxe = ;
const int INF = 0x3f3f3f;
const double eps = 1e-;
const double PI = acos(-1.0); struct Point{
double x,y;
Point(double x=, double y=) : x(x),y(y){ } //构造函数
};
typedef Point Vector; Vector operator + (Vector A , Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Vector A , Vector B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (Vector A , double p){return Vector(A.x*p,A.y*p);}
Vector operator / (Vector A , double p){return Vector(A.x/p,A.y/p);} bool operator < (const Point& a,const Point& b){
return a.x < b.x ||( a.x == b.x && a.y < b.y);
} int dcmp(double x){
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
bool operator == (const Point& a, const Point& b){
return dcmp(a.x - b.x) == && dcmp(a.y - b.y) == ;
} ///向量(x,y)的极角用atan2(y,x);
double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; }
double Length(Vector A) { return sqrt(Dot(A,A)); }
double Angle(Vector A, Vector B) { return acos(Dot(A,B) / Length(A) / Length(B)); } double Cross(Vector A, Vector B) { return A.x*B.y - A.y * B.x; }
double Area2(Point A,Point B,Point C) { return Cross(B-A,C-A); } bool SegmentIntersection(Point a1, Point a2, Point b1, Point b2) {
bool flag = max(a1.x, a2.x) >= min(b1.x, b2.x) && max(b1.x, b2.x) >= min(a1.x, a2.x) &&
max(a1.y, a2.y) >= min(b1.y, b2.y) && max(b1.y, b2.y) >= min(a1.y, a2.y);
double c1 = Cross(a2-a1,b1-a1), c2 = Cross(a2-a1,b2-a1),
c3 = Cross(b2-b1,a1-b1), c4 = Cross(b2-b1,a2-b1);
return flag && dcmp(c1) * dcmp(c2) < && dcmp(c3) * dcmp(c4) < ;
} bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2){
double c1 = Cross(a2-a1,b1-a1), c2 = Cross(a2-a1,b2-a1),
c3 = Cross(b2-b1,a1-b1), c4 = Cross(b2-b1,a2-b1);
return dcmp(c1) * dcmp(c2) < && dcmp(c3) * dcmp(c4) < ;
} struct Edge{
int u,v;
double w;
int next;
void assign(int u_,int v_,double w_,int next_){
u = u_; v = v_; w = w_; next = next_;
}
bool operator < (const Edge& r) const{
return w > r.w;
}
}edges[maxe]; struct Dijkstra{
int s,t;
int head[maxn];
int cnt;
double d[maxn]; void addedge(int u,int v,double w){
edges[cnt].assign(u,v,w,head[u]);
head[u] = cnt++;
} void init(int s_,int t_){
s = s_; t = t_;
cnt = ;
memset(head,-,sizeof(head));
} double dijkstra(){
priority_queue<Edge> Q;
while(!Q.empty()) Q.pop();
for(int i=;i<=maxn;i++) d[i] = INF;
bool vis[maxn];
memset(vis,,sizeof(vis));
Edge edge = {s,,};
Q.push(edge); d[s] = ;
while(!Q.empty()){
Edge e = Q.top() ; Q.pop() ;
int u = e.u;
if(vis[u]) continue;
vis[u] = true;
for(int i=head[u];i!=-;i=edges[i].next){
int v = edges[i].v;
if( d[v] > d[u] + edges[i].w){
d[v] = d[u] + edges[i].w;
Edge edge = {v,,d[v]};
Q.push(edge);
}
}
}
return d[t];
}
}; /************************分割线****************************/ Point P[maxn][];
int n;
Dijkstra solver;
int main()
{
//freopen("E:\\acm\\input.txt","r",stdin); while(cin>>n && n != -){
solver.init(,*n+);
P[][] =Point(,); P[n+][] =Point(,);
for(int i=;i<=n;i++){
double x,y;
scanf("%lf",&x);
for(int j=;j<=;j++){
scanf("%lf",&y);
P[i][j]=Point(x,y);
}
} for(int i=;i<=n;i++){
if(i==){
for(int j=i+;j<=n;j++)
for(int k=;k<=;k++){
int flag = true;
for(int m=;m<=j-;m++){
Point a1=P[m][],a2=P[m][],b1=P[m][],b2=P[m][];
if(!SegmentIntersection(P[][],P[j][k],a1,a2) && !SegmentIntersection(P[][],P[j][k],b1,b2)){
flag = false; break;
}
}
if(flag){
solver.addedge(,*j+k-,Length(P[][]-P[j][k]));
}
}
int flag = true;
for(int m=;m<=n;m++){
Point a1=P[m][],a2=P[m][],b1=P[m][],b2=P[m][];
if(!SegmentIntersection(P[][],P[n+][],a1,a2) && !SegmentIntersection(P[][],P[n+][],b1,b2)){
flag = false; break;
}
}
if(flag){
solver.addedge(,*n+,Length(P[][]-P[n+][]));
} }
else{
for(int h=;h<=;h++){ //确定点P[i][h]
for(int j=i+;j<=n;j++)
for(int k=;k<=;k++){ //确定点p[j][k];
int flag = true;
for(int m=i+;m<=j-;m++){
Point a1=P[m][],a2=P[m][],b1=P[m][],b2=P[m][];
if(!SegmentIntersection(P[i][h],P[j][k],a1,a2)&&!SegmentIntersection(P[i][h],P[j][k],b1,b2)){
flag = false; break;
}
}
if(flag){
solver.addedge(*i+h-,*j+k-,Length(P[i][h]-P[j][k]));
}
}
int flag = true;
for(int m=i+;m<=n;m++){
Point a1=P[m][],a2=P[m][],b1=P[m][],b2=P[m][];
if(!SegmentIntersection(P[i][h],P[n+][],a1,a2)&&!SegmentIntersection(P[i][h],P[n+][],b1,b2)){
flag = false; break;
}
}
if(flag){
solver.addedge(*i+h-,*n+,Length(P[i][h]-P[n+][]));
}
}
}
}
printf("%.2f\n",solver.dijkstra());
}
}

poj 1556 The door的更多相关文章

  1. 最短路+线段交 POJ 1556 好题

    // 最短路+线段交 POJ 1556 好题 // 题意:从(0,5)到(10,5)的最短距离,中间有n堵墙,每堵上有两扇门可以通过 // 思路:先存图.直接n^2来暴力,不好写.分成三部分,起点 终 ...

  2. POJ 1556 - The Doors 线段相交不含端点

    POJ 1556 - The Doors题意:    在 10x10 的空间里有很多垂直的墙,不能穿墙,问你从(0,5) 到 (10,5)的最短距离是多少.    分析:        要么直达,要么 ...

  3. POJ 1556 The Doors 线段交 dijkstra

    LINK 题意:在$10*10$的几何平面内,给出n条垂直x轴的线,且在线上开了两个口,起点为$(0, 5)$,终点为$(10, 5)$,问起点到终点不与其他线段相交的情况下的最小距离. 思路:将每个 ...

  4. poj 1556 (Dijkstra + Geometry 线段相交)

    链接:http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  5. poj 1556 zoj1721 BellmanFord 最短路+推断直线相交

    http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions ...

  6. POJ 1556 - The Doors - [平面几何+建图spfa最短路]

    题目链接:http://poj.org/problem?id=1556 Time Limit: 1000MS Memory Limit: 10000K Description You are to f ...

  7. POJ 1556 The Doors【最短路+线段相交】

    思路:暴力判断每个点连成的线段是否被墙挡住,构建图.求最短路. 思路很简单,但是实现比较复杂,模版一定要可靠. #include<stdio.h> #include<string.h ...

  8. 【POJ 1556】The Doors 判断线段相交+SPFA

    黑书上的一道例题:如果走最短路则会碰到点,除非中间没有障碍. 这样把能一步走到的点两两连边,然后跑SPFA即可. #include<cmath> #include<cstdio> ...

  9. poj 1556 The Doors

    The Doors Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u   Java ...

随机推荐

  1. .NET中的三种Timer的区别和用法(转)

      最近正好做一个WEB中定期执行的程序,而.NET中有3个不同的定时器.所以正好研究研究.这3个定时器分别是: //1.实现按用户定义的时间间隔引发事件的计时器.此计时器最宜用于 Windows 窗 ...

  2. Getopt::Long 模块的简单使用

    用法简介 1.带值参数传入程序内部 ※参数类型:整数, 浮点数, 字串 GetOptions( 'tag=s' => \$tag ); ‘=’表示此参数一定要有参数值, 若改用’:'代替表示参数 ...

  3. CentOS 忘记root密码,解决方法

    1.开机后,在倒数5秒结束前,按下任意键 2.在显示centos...的那个界面下,按e键(edit) 3.会出现三行的界面,选择中间 kernel...那行,然后按e键 4.在接着出现的那个界面最后 ...

  4. html中发送邮箱的链接

  5. Windows手动搭建PHP运行环境

    首先~可以先在目录里面创建一个wamp目录,我的创建在 E: 盘 1.0 下载Apache2.4,x64位.VC11组件[电脑多少位装多少位] apache下载地址:https://www.apach ...

  6. 假金币问题-PKUacm1029-ACM

    假金币 “Gold Bar”银行收到可靠消息:在前次的N 个金币中有一枚重量不同的假金币(其他金币的重量都相同).经济危机之后他们只有一台天平可用.用这台天平,可以称量出左边托盘中的物体是轻于.重于或 ...

  7. 基于BitNami for XAMPP进行Drupal7安装的教程(Win7平台)

    BitNami是一个开源项目,该项目产生的开源软件包可用于安装Web应用程序和解决方案堆栈,以及虚拟设备.BitNami 提供wordpress.joomla.drupal.bbpress等开源程序的 ...

  8. unix-环境高级编程-读书笔记与习题解答-第三篇

    第一章 第五节 进程与控制 该小节比较粗略的阐述了unix操作系统中用于进程控制的三个函数,分别为 : fork , exec, waitpid, 其中 exec 有五种变体, 这些变体实现的功能全部 ...

  9. Objective-C基础 便利构造器 单例模式1-17

    Objective-C基础 便利构造器 单例模式1-17 便利构造器 单例模式 1.在声明时指定setter或getter方法,则用点运算符方法调用时默认调用的就是自己指定的方法2.单例:唯一性,如: ...

  10. iOS触摸事件处理--备用

    主要是记录下iOS的界面触摸事件处理机制,然后用一个实例来说明下应用场景. 一.处理机制 界面响应消息机制分两块,(1)首先在视图的层次结构里找到能响应消息的那个视图.(2)然后在找到的视图里处理消息 ...