当前位置: 首页 > 编程日记 > 正文

POJ 1556 The Doors(计算几何+最短路)

这题就是,处理出没两个点。假设能够到达,就连一条边,推断可不能够到达,利用线段相交去推断就可以。最后求个最短路就可以

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;struct Point {double x, y;Point() {}Point(double x, double y) {this->x = x;this->y = y;}void read() {scanf("%lf%lf", &x, &y);}
};typedef Point Vector;Vector operator - (Vector A, Vector B) {return Vector(A.x - B.x, A.y - B.y);
}const double eps = 1e-8;int dcmp(double x) {if (fabs(x) < eps) return 0;else return x < 0 ? -1 : 1;
}double Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} //叉积//能够不规范相交
bool SegmentProperIntersection2(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 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) &&dcmp(c1) * dcmp(c2) <= 0 && dcmp(c3) * dcmp(c4) <= 0;
}const int N = 25;int n;struct Ban {Point p[4];void read() {double a, y[4];scanf("%lf", &a);for (int i = 0; i < 4; i++) {scanf("%lf", &y[i]);p[i] = Point(a, y[i]);}}
} b[N];struct Edge {int u, v;double w;Edge(){}Edge(int u, int v, double w) {this->u = u;this->v = v;this->w = w;}
};vector<Edge> g[N * 4];double dist(Point a, Point b) {double dx = a.x - b.x;double dy = a.y - b.y;return sqrt(dx * dx + dy * dy);
}void add_edge(int u, int v, double d) {g[u].push_back(Edge(u, v, d));g[v].push_back(Edge(v, u, d));
}bool judge(int l, int r, Point aa, Point bb) {for (int i = l; i <= r; i++) {if (!SegmentProperIntersection2(aa, bb, b[i].p[0], b[i].p[1]) && !SegmentProperIntersection2(aa, bb, b[i].p[2], b[i].p[3]))return false;}return true;
}double d[N * 4];
int vis[N * 4];double spfa(int s, int t) {memset(vis, 0, sizeof(vis));queue<int> Q;for (int i = 0; i <= t; i++) d[i] = 1e20;d[0] = 0;vis[0] = 1;Q.push(0);while (!Q.empty()) {int u = Q.front();Q.pop();vis[u] = 0;for (int i = 0; i < g[u].size(); i++) {int v = g[u][i].v;double w = g[u][i].w;if (d[u] + w < d[v]) {d[v] = d[u] + w;if (!vis[v]) {vis[v] = 1;Q.push(v);}}}}return d[t];
}int main() {while (~scanf("%d", &n) && n != -1) {for (int i = 0; i <= n * 4 + 1; i++) g[i].clear();for (int i = 0; i < n; i++)b[i].read();if (judge(0, n - 1, Point(0, 5), Point(10, 5)))add_edge(0, n * 4 + 1, 10);for (int i = 0; i < n; i++) {for (int j = 0; j < 4; j++) {if (judge(0, i - 1, Point(0, 5), b[i].p[j]))add_edge(0, i * 4 + j + 1, dist(Point(0, 5), b[i].p[j]));if (judge(i + 1, n - 1, b[i].p[j], Point(10, 5)))add_edge(n * 4 + 1, i * 4 + j + 1, dist(Point(10, 5), b[i].p[j]));for (int k = i + 1; k < n; k++) {for (int x = 0; x < 4; x++) {if (judge(i + 1, k - 1, b[i].p[j], b[k].p[x]))add_edge(i * 4 + j + 1, k * 4 + x + 1, dist(b[i].p[j], b[k].p[x]));}}}}printf("%.2f\n", spfa(0, n * 4 + 1));}return 0;
}


转载于:https://www.cnblogs.com/bhlsheji/p/5247058.html

相关文章:

* core-js/modules/es6.array.fill in ./node_modules/_cache-loader@2.0.1@cache-loader/dist/cjs.js??ref

运行Vue项目报错&#xff0c;报错截图如下&#xff1a; 导致该错误的原因是core-js版本不对&#xff1a; 解决方法&#xff1a;安装淘宝镜像 $ cnpm install core-js2 安装完成重新运行就可以了 外&#xff1a; 清除npm缓存命令 &#xff1a; npm cache clean -f

github创建静态页面_如何在10分钟内使用GitHub Pages创建免费的静态站点

github创建静态页面Static sites have become all the rage, and with good reason – they are blazingly fast and, with an ever growing number of supported hosting services, pretty easy to set up. 静态站点已成为流行&#xff0c;并且有充分的理由-它们非常快速&…

小程序生成网址链接,网址链接跳转小程序

登录小程序后台&#xff0c;点击右上角的工具&#xff0c;生成小程序URL Scheme &#xff0c; 可以得出一个 weixin://dl/business/?tbAXXXXX 这样的链接&#xff0c;点击就可以调整到小程序拉&#xff0c;但是这种只能在微信打开哦。

appium-chromedriver@3.0.1 npm ERR! code ELIFECYCLE npm ERR! errno 1

解决方法&#xff1a; npm install appium-chromedriver3.0.1 --ignore-scripts 或者&#xff08;安装方法&#xff09;&#xff1a; npm install appium-chromedriver --chromedriver_cdnurlhttp://npm.taobao.org/mirrors/chromedriver 官网地址&#xff1a;https://www.npmj…

linux下QT Creator常见错误及解决办法

最近因为在做一个关于linux下计算机取证的小项目&#xff0c;需要写一个图形界面&#xff0c;所以想到了用QT来写&#xff0c;选用了linux下的集成开发环境QT Creator5.5.1&#xff0c;但刚刚安装好&#xff0c;竟然连一个"hello world"的样例都跑不起来&#xff0c;…

如何使用JavaScript Math.floor生成范围内的随机整数-已解决

快速解决方案 (Quick Solution) function randomRange(myMin, myMax) {return Math.floor(Math.random() * (myMax - myMin 1) myMin); }代码说明 (Code Explanation) Math.random() generates our random number between 0 and ≈ 0.9. Math.random()生成介于0和≈0.9之间的…

小白的未来与展望

新的起点&#xff0c;新的挑战与机遇 1.在php制作&#xff0c;研发上的知识点及语法编辑重点要按照老师的要求完全掌握。作为对自己以后前进方向上坚实的基础。 2.php语言开发编写上&#xff0c;希望能够在不久的将来能够有自己的独特的理解及研发出更多的更为简洁方便的编写方…

uniapp移动端H5在线预览PDF等文件实现源码及注解

uniapp移动端H5预览文件实现分为两个场景处理: (这里以预览PDF文件为示例,在线预览就是查看网络文件) 1. IOS客户端预览PDF文件 IOS客户端预览PDF文件可以通过跳转文件地址实现预览,因为苹果手机的浏览器自带阅读器 2. 安卓客户端预览PDF文件 安卓客户端需要在源码添…

如何使用Python和Tkinter构建Toy Markdown编辑器

Markdown editors are trending these days. Everybody is creating a markdown editor, and some of them are innovative while some of them are boring. Markdown编辑器近来呈趋势。 每个人都在创建降价编辑器&#xff0c;其中有些人很创新&#xff0c;而有些人很无聊。 A…

Hadoop 分布式环境搭建

1.集群机器&#xff1a; 1台 装了 ubuntu 14.04的 台式机 1台 装了ubuntu 16.04 的 笔记本 &#xff08;机器更多时同样适用&#xff09; 搭建步骤&#xff1a; 准备工作&#xff1a; 使两台机器处于同一个局域网&#xff1a;相互能够 ping 通 主机名称 …

常见报错——Uncaught TypeError: document.getElementsByClassName(...).addEventListener is not a function...

这是因为选择器没有正确选择元素对象 document.getElementsByClassName(...)捕捉到的是该类名元素的数组 正确的访问方式应该是&#xff1a; document.getElementsByClassName(...)[0].addEventListener... 使用遍历为每个class添加监听&#xff1a; var classObj document.ge…

uniapp富文本兼容视频实现方案

使用 mp-html 富文本插件&#xff0c;就可以支持富文本内的视频播放。 安装&#xff1a; npm install mp-html 使用方法 <template><view><mp-html :content"html" /></view> </template> <script>import mpHtml from /comp…

循环神经网络 递归神经网络_如何用递归神经网络预测空气污染

循环神经网络 递归神经网络After the citizen science project of Curieuze Neuzen, I wanted to learn more about air pollution to see if I could make a data science project out of it. On the website of the European Environment Agency, you can find a huge amount…

mysql like 命中索引

反向索引案例&#xff1a;CREATE TABLE my_tab(x VARCHAR2(20)); INSERT INTO my_tab VALUES(abcde); COMMIT;CREATE INDEX my_tab_idx ON my_tab(REVERSE(x)); SELECT * FROM my_tab t WHERE REVERSE(t.x) LIKE REVERSE(%cde);//避免使用like时索引不起作用 修改反向索引为正…

CSS超出隐藏并且能滚动

效果图 实现CSS代码&#xff1a; height: 500rpx; overflow-x: hidden; overflow-y: scroll; 效果图的代码&#xff1a; <!-- 豆豆明细弹窗 --><view class"mxBoom" v-show"mxBoom"><view class"mxBoomContent"><view c…

Oracle学习之段区块初步概念

段&#xff1a;一张表可以视为一个段 区&#xff1a;Oracle 给段分配空间的最小单位&#xff0c;表建好后&#xff0c;Oracle就会给表分配物理上连续的空间&#xff0c;叫做区 块&#xff1a;Oracle IO的最小单位&#xff0c;buffer cache中缓存的是dbf文件&#xff0c;由于dbf…

github充当服务器_如何创建充当链接HTML按钮

github充当服务器Sometimes you may want to use a button to link to another page or website rather than to submit a form or something like that. This is fairly simple to do and can be achieved in several ways.有时&#xff0c;您可能希望使用按钮链接到另一个页面…

provide和inject,Vue父组件直接给孙子组件传值

Provide / Inject 该页面假设你已经阅读过了组件基础。如果你还对组件不太了解&#xff0c;推荐你先阅读它。 通常&#xff0c;当我们需要从父组件向子组件传递数据时&#xff0c;我们使用 props。想象一下这样的结构&#xff1a;有一些深度嵌套的组件&#xff0c;而深层的子组…

用欧几里得算法求最大公约数_欧几里得算法:GCD(最大公约数),用C ++和Java示例解释...

用欧几里得算法求最大公约数For this topic you must know about Greatest Common Divisor (GCD) and the MOD operation first.对于本主题&#xff0c;您必须首先了解最大公约数(GCD)和MOD操作。 最大公约数(GCD) (Greatest Common Divisor (GCD)) The GCD of two or more in…

eclipse 重启/打开内置浏览器

重启 Eclipse 重启选项允许用户重启 Eclipse。 我们可以通过点击 File 菜单选择 Restart 菜单项来重启 Eclipse。 Eclipse 内置浏览器 Web 浏览器 Eclipse 系统内部自带了浏览器&#xff0c;该浏览器可以通过点击 Window 菜单并选择 Show View > Other&#xff0c;在弹出来的…

JConsole的使用

一、JConsole是什么 从Java 5开始 引入了 JConsole。JConsole 是一个内置 Java 性能分析器&#xff0c;可以从命令行或在 GUI shell 中运行。您可以轻松地使用 JConsole&#xff08;或者&#xff0c;它更高端的 “近亲” VisualVM &#xff09;来监控 Java 应用程序性能和跟踪 …

折线图表动画(历史进程效果)

代码环境:uniapp 秋云uCharts图表组件https://demo.ucharts.cn/#/代码说明: 在插件市场导入插件秋云 ucharts echarts 高性能跨全端图表组件 - DCloud 插件市场uCharts v2.3上线,支持nvue!全新官方图表组件,支持H5及APP用ECharts渲染图表,uniapp可视化首选组件

不要只是为您的代码做些毛-用Prettier修复它

Linting makes our lives easier because it tells us what’s wrong with our code. But how can we avoid doing the actual work that goes into fixing it?Linting使我们的生活更轻松&#xff0c;因为它告诉我们代码有什么问题。 但是&#xff0c;如何避免进行修复工作呢&…

循环语句(2)

for的嵌套 //99乘法表for (int a 1; a < 9; a)-----控制行{for (int i 1; i < a; i)------控制列{Console.Write(i "*" a "" (a * i) "\t");}Console.WriteLine();}Console.ReadLine(); 结果 打印星号 //直角在左上for (int i …

通过Shell脚本将VSS项目批量创建并且提交迁移至Gitlab

脚本运行环境&#xff1a;Git Bash 系统环境&#xff1a;Windows 10 Pro 1709 VSS版本&#xff1a;Microsoft Visual SourceSafe 2005 我的VSS工作目录结构如下&#xff1a; D:\work\ --vss ----project1 ------src ------README.md ------ ...... ----project2 ------doc ----…

样式集(11)注册页面样式,全部代码附效果图

效果图&#xff1a; 代码&#xff1a; <template><view class"page"><view class"top">新用户注册</view><image :src"sanjiao" mode"widthFix" class"sanjiao"></image><!-- <…

quickselect_QuickSelect:使用代码示例解释的快速选择算法

quickselect什么是QuickSelect&#xff1f; (What is QuickSelect?) QuickSelect is a selection algorithm to find the K-th smallest element in an unsorted list.QuickSelect是一种选择算法&#xff0c;用于在未排序的列表中查找第K个最小的元素。 算法说明 (The Algori…

《Linux命令行与shell脚本编程大全 第3版》Shell脚本编程基础---34

以下为阅读《Linux命令行与shell脚本编程大全 第3版》的读书笔记&#xff0c;为了方便记录&#xff0c;特地与书的内容保持同步&#xff0c;特意做成一节一次随笔&#xff0c;特记录如下&#xff1a;转载于:https://www.cnblogs.com/guochaoxxl/p/7894620.html

CSS超出部分隐藏,显示滚动条

实现功能&#xff1a; 固定一个高度&#xff0c;超出该高度的部分就隐藏&#xff0c;并且显示滚动条能上拉下滑滚动 实现代码&#xff1a; height: 500rpx; overflow-x: hidden; overflow-y: scroll; 实现功能&#xff1a; 固定一个宽度&#xff0c;超出该宽度的部分就隐藏…

第二周学习进度

好久的编程实现&#xff0c;居然没有编完整&#xff0c;看来自己需要加班学习了&#xff01;第二周学习进度如下&#xff1a; 第二周所花时间&#xff08;包括上课&#xff09;共计21小时代码量&#xff08;行&#xff09;220博客量&#xff08;篇&#xff09;4了解到的知识 1.…