博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Poj 1556 The Doors 计算几何+最短路
阅读量:4307 次
发布时间:2019-06-06

本文共 2111 字,大约阅读时间需要 7 分钟。

其实本题非常的无脑,无脑拍完1A,写到blog里只因为TM无脑拍也拍了很久啊= =

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long LL;const int maxn = 2000;const int maxm = 2000 * 2000; const double INF = 1e30;const double eps = 1e-7;struct Point { double x,y; Point(double x = 0,double y = 0):x(x),y(y) {}};Point str(0,5),end(10,5);vector
p,pw;double dist[maxn][maxn],d[maxn];int N,M;int dcmp(double x) { if(fabs(x) < eps) return 0; if(x < 0) return -1; return 1;}Point operator - (Point a,Point b) { return Point(a.x - b.x,a.y - b.y);}double Cross(Point a,Point b) { return a.x * b.y - a.y * b.x;}double Dot(Point a,Point b) { return a.x * b.x + a.y * b.y;}bool SegmentCross(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) < 0 && dcmp(c3) * dcmp(c4) < 0;}bool nonecross(Point a1,Point a2) { for(int i = 0;i < pw.size();i += 2) { if(SegmentCross(a1,a2,pw[i],pw[i + 1])) return false; } return true;}void solve() { //构建邻接矩阵 M = p.size(); for(int i = 0;i < M;i++) { for(int j = i + 1;j < M;j++) { if(nonecross(p[i],p[j])) { dist[i][j] = dist[j][i] = sqrt(Dot(p[i]-p[j],p[i]-p[j])); } else dist[i][j] = INF; } } //bellman-ford for(int i = 0;i < M;i++) d[i] = INF; d[0] = 0; for(int i = 0;i < M;i++) { for(int j = 0;j < M;j++) { for(int k = 0;k < M;k++) if(dist[j][k] < INF) { if(d[j] < INF) { d[k] = min(d[k],d[j] + dist[j][k]); } } } } printf("%.2f\n",d[M - 1]);}int main() { while(cin >> N,N != -1) { p.clear(); pw.clear(); p.push_back(Point(0,5)); for(int i = 1;i <= N;i++) { double posx,posy; cin >> posx; pw.push_back(Point(posx,0)); for(int j = 0;j < 4;j++) { cin >> posy; p.push_back(Point(posx,posy)); pw.push_back(Point(posx,posy)); } pw.push_back(Point(posx,10)); } p.push_back(Point(10,5)); solve(); } return 0;}

  

转载于:https://www.cnblogs.com/rolight/p/3849494.html

你可能感兴趣的文章
eclipse安装插件的两种方式在线和离线
查看>>
linux下源的相关笔记(suse)
查看>>
linux系统分区文件系统划分札记
查看>>
Linux(SUSE 12)安装Tomcat
查看>>
Linux(SUSE 12)安装jboss4并实现远程访问
查看>>
Neutron在给虚拟机分配网络时,底层是如何实现的?
查看>>
netfilter/iptables全攻略
查看>>
Overlay之VXLAN架构
查看>>
Eclipse : An error occurred while filtering resources(Maven错误提示)
查看>>
在eclipse上用tomcat部署项目404解决方案
查看>>
web.xml 配置中classpath: 与classpath*:的区别
查看>>
suse如何修改ssh端口为2222?
查看>>
详细理解“>/dev/null 2>&1”
查看>>
suse如何创建定时任务?
查看>>
suse搭建ftp服务器方法
查看>>
centos虚拟机设置共享文件夹并通过我的电脑访问[增加smbd端口修改]
查看>>
文件拷贝(IFileOperation::CopyItem)
查看>>
MapReduce的 Speculative Execution机制
查看>>
大数据学习之路------借助HDP SANDBOX开始学习
查看>>
Hadoop基础学习:基于Hortonworks HDP
查看>>