哦天哪这个萨比提又浪费了我好几个小时。

我们在check的时候只考虑严格相交就行了,想了很久才注意到这一点。

然后就建图跑最短路,over。

 #include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <iomanip>
#include <iostream>
typedef double db;
using namespace std;
const db eps=1e-;
const db pi=acos(-);
int sign(db k){
if (k>eps) return ; else if (k<-eps) return -; return ;
}
int cmp(db k1,db k2){return sign(k1-k2);}
struct point{
db x,y;
point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};}
point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};}
point operator * (db k1) const{return (point){x*k1,y*k1};}
point operator / (db k1) const{return (point){x/k1,y/k1};}
db abs(){ return sqrt(x*x+y*y);}
db dis(point k1){ return(*this-k1).abs();}
};
db cross(point k1,point k2){ return k1.x*k2.y-k1.y*k2.x; }
db dot(point k1,point k2){ return k1.x*k2.x+k1.y*k2.y;}
int intersect(db l1,db r1,db l2,db r2){
if (l1>r1) swap(l1,r1); if (l2>r2) swap(l2,r2); return cmp(r1,l2)!=-&&cmp(r2,l1)!=-;
}
int checkSS(point k1,point k2,point k3,point k4){
return //intersect(k1.x,k2.x,k3.x,k4.x)&&intersect(k1.y,k2.y,k3.y,k4.y)&&
sign(cross(k3-k1,k4-k1))*sign(cross(k3-k2,k4-k2))<&&
sign(cross(k1-k3,k2-k3))*sign(cross(k1-k4,k2-k4))<;
}
struct line{
point p[];
};
int checkSS(line a,line b){
return checkSS(a.p[],a.p[],b.p[],b.p[]);
}
int n;
db dis[];
struct node { //堆节点
int u;db d;
bool operator <(const node& rhs) const {
return d>rhs.d;
}
};
struct Edge { int v,nxt;db w;};
Edge e[];
int head[],cnt=;
void addEdge(int u,int v,db w) {
e[++cnt].v=v;
e[cnt].w=w;
e[cnt].nxt=head[u];
head[u]=cnt;
}
void Dijkstra() {
for (int i=;i<=;i++) dis[i]=;
dis[]=;
priority_queue<node> Q; //堆
Q.push((node){,});
while (!Q.empty()) {
node fr=Q.top(); Q.pop();
int u=fr.u;db d=fr.d;
if (cmp(d,dis[u])>) continue;
for (int i=head[u];i;i=e[i].nxt) {
int v=e[i].v;db w=e[i].w;
if (cmp(dis[u]+w,dis[v])<) {
dis[v]=dis[u]+w;
Q.push((node){v,dis[v]});
}
}
}
}
db yl,y2,y3,y4,x;
vector<line> v;
vector<point> g;
bool check(line tmp){
for(int i=;i<v.size();i++){
if(checkSS(tmp,v[i])){
return false;
}//return false;
}
return true;
}
int main(){
ios::sync_with_stdio(false);
cout<<fixed<<setprecision();
while (cin>>n&&n!=-){
g.push_back(point{,});
for(int i=;i<=n;i++){
cin>>x>>yl>>y2>>y3>>y4;
g.push_back(point{x,yl});
g.push_back(point{x,y2});
g.push_back(point{x,y3});
g.push_back(point{x,y4});
v.push_back(line{point{x,},point{x,yl}});
v.push_back(line{point{x,y2},point{x,y3}});
v.push_back(line{point{x,y4},point{x,}});
}
g.push_back(point{,});
int m=g.size();
for(int i=;i<m;i++){
for(int j=i+;j<m;j++){
if(check(line{g[i],g[j]})){
//printf("%d %d\n",i,j);
addEdge(i,j,g[i].dis(g[j]));
addEdge(j,i,g[i].dis(g[j]));
}
}
}
Dijkstra();
cout<<dis[m-]<<endl;
g.clear();
v.clear();
cnt=;
memset(head,, sizeof(head));
}
}
/**
2
4 2 7 8 9
7 3 4.5 6 7
-1
*/

poj 1556的更多相关文章

  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 The door

    题目链接:http://poj.org/problem?id=1556 #include<cstdio> #include<cstring> #include<cmath ...

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

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

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

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

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

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

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

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

  10. poj 1556 The Doors

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

随机推荐

  1. 9、js扩展

    作用域是JavaScript最重要的概念之一,想要学好JavaScript就需要理解JavaScript作用域和作用域链的工作原理. 本片导航: js的作用域 作用域链(Scope Chain) 一. ...

  2. 发送HTTPS请求

    package com.suning.epp.trt.util.r32epp; import java.io.BufferedInputStream; import java.io.IOExcepti ...

  3. 第二天学习笔记:(MDN HTML学习、web安全策略与常见攻击、语义化)

    一:Web入门 1:web文件命名 在文件名中应使用连字符(-).搜索引擎把连字符当作一个词的分隔符, 但不会以这种方式处理下划线. 养成在文件夹和文件名中使用小写,并且使用短横线而不是空格来分隔的习 ...

  4. increase the minSdkVersion to 26

    AGPBI: {"kind":"error","text":"Invoke-customs are only supported ...

  5. CentOS 6.5 x64下网络配置

    一.自动获取IP地址 #dhclient 自动获取ip地址命令 #ifconfig 查询系统里网卡信息,ip地址.MAC地址 [root@CentOS6 ~]# vi /etc/sysconfig/n ...

  6. 【转】WPF 与 WinForm 间的按键值(枚举)转换

    There is a function for that in System.Windows.Input.KeyInterop static class. Try:var inputKey = Key ...

  7. iOS开发下载文件速度计算

    当我们写下载界面的时候,需要向用户展示每秒下载多少KB,这个时候就需要计算速度.如下: 我用的是AFNetworking来做下载的,我们拿AFHTTPRequestOperation来举列,AFHTT ...

  8. sqoop导入数据到hive中元数据问题

    简单配置了sqoop之后开始使用,之前用的时候很好用,也不记得有没有启动hivemetastore,今天用的时候没有启动,结果导入数据时,如果使用了db.tablename,就会出现找不到数据库的错, ...

  9. Windows 使用 Gogs 搭建 Git 服务器(转)

    Windows 使用 Gogs 搭建 Git 服务器   随便说两句 之前有使用 Gitblit 在Windows搭建Git服务器,用的也挺好的,可能安装起来略麻烦一点.现在全用 Gogs 在wind ...

  10. oracle表查询优化

    ORACLE有个高速缓冲的概念,这个高速缓冲就是存放执行过的SQL语句,那oracle在执行sql语句的时候要做很多工作,例如解析sql语句,估算索引利用率,绑定变量,读取数据块等等这些操作.假设高速 ...