[NOI2011]智能车比赛 (计算几何 DAG)
/*
可以发现, 最优路径上的所有拐点, 基本上都满足一定的性质, 也就是说是在矩形上的拐角处
所以我们可以把他们提出来, 单独判断即可
由于我们提出来的不超过2n + 2个点, 我们将其按照x坐标排序, 这样就只能单方向走
n^2枚举判断两个点之间能不能直接走, 然后连边DAGdp即可
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<iostream>
#define ll long long
#define M 4080
#define mmp make_pair
using namespace std;
const double inf = pow(2, 60);
int read() {
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
struct Note {
int x, y, f;
bool operator < (const Note &b) const {
return x == b.x ? y < b.y : x < b.x;
}
} note[M];
int n, m, L, R, lx[M], ly[M], rx[M], ry[M], bex, bey, edx, edy, tp;
vector<pair<int, double> > to[M];
double f[M], v, ans;
double dis(Note a, Note b) {
return sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + 1.0 * (a.y - b.y) * (a.y - b.y));
}
int main() {
n = read();
for(int i = 1; i <= n; i++) lx[i] = read(), ly[i] = read(), rx[i] = read(), ry[i] = read();
bex = read(), bey = read(), edx = read(), edy = read();
if(bex == edx) {
ans = (bey > edy) ? bey - edy : edy - bey;
} else {
if(bex > edx) swap(bex, edx), swap(bey, edy);
note[++tp] = (Note) {
bex, bey, 1
};
note[++tp] = (Note) {
edx, edy, 2
};
for(int i = 1; i < n; i++) {
int maxx = max(ly[i], ly[i + 1]), minn = min(ry[i], ry[i + 1]);
note[++tp] = (Note) {
lx[i + 1], minn, 3
};
note[++tp] = (Note) {
lx[i + 1], maxx, 4
};
}
sort(note + 1, note + tp + 1);
for(int i = 1; i <= tp; i++) {
if(note[i].f == 1) L = i;
if(note[i].f == 2) R = i;
}
for(int i = L; i <= R; i++) {
double le = -inf, re = inf;
for(int j = i + 1; j <= R; j++) {
if(note[j].x == note[i].x) {
to[j].push_back(mmp(i, note[j].y - note[i].y));
continue;
}
double slp = 1.0 * (note[j].y - note[i].y) / (note[j].x - note[i].x);
if(slp >= le && slp <= re) to[j].push_back(mmp(i, dis(note[i], note[j])));
if(note[j].f == 4) le = max(le, slp);
else re = min(re, slp);
}
}
for(int i = L + 1; i <= R; i++) {
f[i] = inf;
for(int j = 0; j < to[i].size(); j++) {
// cout << to[i][j].second << "\n";
f[i] = min(f[i], f[to[i][j].first] + to[i][j].second);
}
}
ans = f[R];
}
cin >> v;
ans /= v;
printf("%.8lf\n", ans);
return 0;
}
[NOI2011]智能车比赛 (计算几何 DAG)的更多相关文章
- 2433: [Noi2011]智能车比赛 - BZOJ
Description 新一届智能车大赛在JL大学开始啦!比赛赛道可以看作是由n个矩形区域拼接而成(如下图所示),每个矩形的边都平行于坐标轴,第i个矩形区域的左下角和右上角坐标分别为(xi,1,yi, ...
- Noi2011 : 智能车比赛
假设S在T左边,那么只能往右或者上下走 f[i]表示S到i点的最短路 f[i]=min(f[j]+dis(i,j)(i能看到j)) 判断i能看到j就维护一个上凸壳和一个下凸壳 时间复杂度$O(n^2) ...
- [bzoj2433][Noi2011]智能车比赛
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2433 http://221.192.240.123:8586/JudgeOnline/ ...
- 【[NOI2011]智能车比赛】(建图+spfa+坑爹精度)
过了这题我就想说一声艹,跟这个题死磕了将近6个小时,终于是把这个题死磕出来了.首先看到这个题的第一反应,和当初做过的一个房间最短路比较相似,然后考虑像那个题那样建边,然后跑最短路.(具体建边方法请参考 ...
- BZOJ 2433 智能车比赛(计算几何+最短路)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2433 题意:若干个矩形排成一排(同一个x之上最多有一个矩形),矩形i和i+1相邻.给定两 ...
- 【LOJ】#2443. 「NOI2011」智能车比赛
题解 显然是个\(n^2\)的dp 我们要找每个点不穿过非赛道区域能到达哪些区域的交点 可以通过控制两条向量负责最靠下的上边界,和最靠上的下边界,检查当前点在不在这两条向量之间即可,对于每个点可以\( ...
- 智能车学习(十五)——K60野火2013版例程
一.中断函数注册方法: 1.格式: 配置某个功能的中断 注册中断函数 开启中断 2.一个例子 pit_init_ms(PIT0,);//定时中断初始化 set_vector_handler(PIT0_ ...
- K60平台智能车开发工作随手记
(图片仅为示例,并不一定固定为这种造型) 第十二届全国大学生智能汽车竞赛有一个分项是光电四轮车的竞速(任务A),Seven她们组采购到的配件使用了freescale Crotex-M4内核的CPU,T ...
- 【sky第二期--PID算法】--【智能车论坛】
[sky第二期--PID算法] 想学PID的可以来[智能车论坛]这里有我发布的资料http://bbs.tekbots.eefocus.com/forum.php?mod=viewthread& ...
随机推荐
- Cookie中的sessionid与JSONP原理
一.首先说明一下cookie中的sessionid的作用. 1.cookie只是一些文本内容,多是键值对的形式,是请求头中的一部分 2.http是无连接的 知道这两点,就可以很容易的理解session ...
- C语言一维数组定义及引用时括号[]内容
一维数组定义:数组名[常量表达式] 一维数组引用:数组名[整型常量或整型表达式] *说明:常量表达式 > 整型表达式 > 整型常量 #define N 100 宏定义没有具体的数据类型, ...
- Binary Tree Path Sum
Given a binary tree, find all paths that sum of the nodes in the path equals to a given number targe ...
- Spring boot 启动报错 Failed to auto-configure a DataSource
1.Spring boot 启动报错 Failed to auto-configure a DataSource 参考资料https://blog.csdn.net/liuyinfei_java/ar ...
- go web framework gin 路由表的设计
在上一篇go web framework gin 启动流程分析这一篇文章中,我分析了go gin启动的过程,在这一篇文章中我将继续上面的分析,讨论gin 中路由表是如何设计的? 首先查看engine. ...
- LSTM学习—Long Short Term Memory networks
原文链接:https://colah.github.io/posts/2015-08-Understanding-LSTMs/ Understanding LSTM Networks Recurren ...
- nginx——Nginx 防爬虫优化
if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediap ...
- linux下的$0-n作用
电面的时候回答上来一部分了....呵呵......总结一下!!! $0 Shell本身的文件名 $1-$n 添加到Shell的各参数值.$1是第1参数.$2是第2参数… $$ Shell本身的PID( ...
- Python学习笔记第二十六周(Django补充)
一.基于jQuery的ajax实现(最底层方法:$.jax()) $.ajax( url: type:''POST“ ) $.get(url,[data],[callback],[type]) #c ...
- ES5和ES6中关于import & export的书写方式的区别
ES6中输出变量的写法 情景1:单个变量 输出 export const less = 'less' 引用 import {less} from '../index.js' 情景2:多个变量 输出: ...