BZOJ 4077 Messenger
Messenger
【问题描述】
alice和bob各自在两条折线上行进,一个邮递员要从alice那拿一个包裹,并以直线移动到bob处,alice和bob、邮递员的速度均为1单位/s,问邮递员最少要走多少秒才能送完包裹。
【输入格式】
【输出格式】
输出只有一行,一个小数,代表邮递员最少要走的时间。若无解,输出impossible
【样例输入】
2
0 0
0 10
2
4 10
4 0
【样例输出】
4.00000
题解:
考虑二分答案
让 Bob 提前走 mid,那么 Alice 与 Bob 的实时距离就是 快递员要走的时间
Check时不断移动,移动的距离是两个人分别与下一个点的距离中的较小值
问题变成了求实时距离(两个人有速度,在不同线段上运动)的最小值
我们以 Alice 为参考系,Bob 匀速移动,并且距离是不变的
就变成了求点(Allice所在位置)到直线(Bob的移动轨迹)的距离、
那么用点积判断是否组成锐角三角形,是的话用叉积求投影,否则就是点与直线两端点的较小值
无解的话 Check( Bob 的总路程) 一下就可以了
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
inline void Scan(int &x)
{
char c;
bool o = false;
while(!isdigit(c = getchar())) o = (c != '-') ? o : true;
x = c - '';
while(isdigit(c = getchar())) x = x * + c - '';
if(o) x = -x;
}
const int maxn = 1e5;
const double inf = 2e10;
const double eps = 1e-;
struct point
{
double x, y;
friend inline point operator + (point a, point b)
{
return (point) {a.x + b.x, a.y + b.y};
}
friend inline point operator - (point a, point b)
{
return (point) {a.x - b.x, a.y - b.y};
}
friend inline point operator * (point a, double x)
{
return (point) {a.x * x, a.y * x};
}
friend inline point operator / (point a, double x)
{
return (point) {a.x / x, a.y / x};
}
friend inline double operator * (point a, point b)
{
return a.x * b.y - a.y * b.x;
}
friend inline double operator ^ (point a, point b)
{
return a.x * b.x + a.y * b.y;
}
inline void print()
{
printf("x=%.2lf y=%.2lf\n", x, y);
}
};
struct ele
{
int n;
double t;
point p;
void print()
{
printf("n=%d t=%.2lf ", n, t);
p.print();
}
};
inline double Sqr(double x)
{
return x * x;
}
inline double Dis(point a, point b)
{
return sqrt(Sqr(a.x - b.x) + Sqr(a.y - b.y));
}
inline int Sgn(double x)
{
if(x < -eps) return -;
if(x > eps) return ;
return ;
}
inline double Dis(point a, point b, point c)
{
if(Sgn(Dis(b, c)))
if(Sgn((a - b) ^ (c - b)) >= && Sgn((a - c) ^ (b - c)) >= )
return fabs(((a - b) * (c - b)) / Dis(b, c));
return min(Dis(a, b), Dis(a, c));
}
struct thing
{
int n;
point p[maxn];
double s[maxn];
inline void Read()
{
Scan(n);
for(int i = ; i <= n; ++i)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
if(i > ) s[i] = s[i - ] + Dis(p[i], p[i - ]);
}
}
};
thing a, b;
inline point Pos(bool o, double x, int p)
{
if(o) return b.p[p] + (b.p[p + ] - b.p[p]) * (x / (b.s[p + ] - b.s[p]));
return a.p[p] + (a.p[p + ] - a.p[p]) * (x / (a.s[p + ] - a.s[p]));
}
point va, vb, dv;
inline double Mini(point a, point b, point c, point d, double dis)
{
va = (b - a) / Dis(a, b);
vb = (d - c) / Dis(c, d);
dv = vb - va;
d = c + dv * dis;
return Dis(a, c, d);
}
inline bool Check(double mid)
{
ele u, v;
u = (ele) {, , a.p[]};
int n = upper_bound(b.s + , b.s + + b.n, mid) - b.s - ;
double s = mid - b.s[n];
v = (ele) {n, s, Pos(true, s, n)};
int x, y;
double l, r, res;
while(true)
{
if(Dis(u.p, v.p) < mid + eps) return true;
if(u.n == a.n || v.n == b.n) break;
x = u.n + , y = v.n + ;
l = Dis(u.p, a.p[x]), r = Dis(v.p, b.p[y]);
res = Mini(u.p, a.p[x], v.p, b.p[y], min(l, r));
if(res < mid + eps) return true;
if(!Sgn(l - r))
{
u = (ele) {x, , a.p[x]};
v = (ele) {y, , b.p[y]};
continue;
}
if(l < r)
{
u = (ele) {x, , a.p[x]};
v.t += l;
v.p = Pos(true, v.t, v.n);
}
else
{
u.t += r;
u.p = Pos(false, u.t, u.n);
v = (ele) {y, , b.p[y]};
}
}
return false;
}
inline double Two()
{
int num = ;
double mi;
double l = , r = b.s[b.n];
while(num--)
{
mi = (l + r) / 2.0;
if(Check(mi)) r = mi;
else l = mi;
}
if(Check(l)) return l;
return r;
}
int main()
{
a.Read();
b.Read();
if(!(Check(b.s[b.n])))
{
printf("impossible\n");
return ;
}
printf("%.5lf", Two());
}
BZOJ 4077 Messenger的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 2127: happiness [最小割]
2127: happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1815 Solved: 878[Submit][Status][Di ...
- android:使用Messenger进行进程间通信(一)
Messenger简介 Messenger和AIDL是实现进程间通信(interprocess communication)的两种方式. 实际上,Messenger的实现其实是对AIDL的封装. Me ...
- BZOJ 3275: Number
3275: Number Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 874 Solved: 371[Submit][Status][Discus ...
- BZOJ 2879: [Noi2012]美食节
2879: [Noi2012]美食节 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1834 Solved: 969[Submit][Status] ...
- bzoj 4610 Ceiling Functi
bzoj 4610 Ceiling Functi Description bzoj上的描述有问题 给出\(n\)个长度为\(k\)的数列,将每个数列构成一个二叉搜索树,问有多少颗形态不同的树. Inp ...
- BZOJ 题目整理
bzoj 500题纪念 总结一发题目吧,挑几道题整理一下,(方便拖板子) 1039:每条线段与前一条线段之间的长度的比例和夹角不会因平移.旋转.放缩而改变,所以将每条轨迹改为比例和夹角的序列,复制一份 ...
- 【sdoi2013】森林 BZOJ 3123
Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M,T,分别表示节点数.初始边数.操作数.第三行包含N个非负整数 ...
- 【清华集训】楼房重建 BZOJ 2957
Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...
随机推荐
- skynet 学习笔记-sproto模块(2)
云风在skynet中继承了sproto的传输协议,对比protobuf的好处是,能明文看到传输内容,而且skynet不需要protobuf这么功能,所以云风也建议在lua层使用sproto来作为sky ...
- SVN:The working copy is locked due to a previous error (一)
使用 Cornerstone 时,碰到如题问题,SVN无法Update.Commit等操作. 解决办法:Working Copies ⟹ '右键' ⟹ Clean 即可解决! 尊重作者劳动成果,转载 ...
- const,static,extern,#define
一.const // 简单定义变量,可以修改变量的值 ; a = ; // const的用法 // 用法一: ; ; // 不允许修改,因为 const 修饰 b/c,指定 b/c 为常量!! // ...
- Docker 镜像&仓库 获取及推送镜像
docker查看.删除镜像 docker镜像存储位置: /var/lib/docker 查看docker信息也可以查看保存位置 docker info 1.列出镜像 docker images -aa ...
- Oracle rownum的理解
核心过程分三步: 从表中取出行(无索引的话,顺序取出). 根据当前结果集,为当前行添加rownum. 条件筛选,如通过则添加到结果集中. 完.
- 如何用纯 CSS 创作一个文本淡入淡出的 loader 动画
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/ERwpeG 可交互视频 ...
- 前端MVVM模式及其在Vue和React中的体现
MVVM相关概念 Mvvm 前端数据流框架精讲 1) MVVM典型特点是有四个概念:Model.View.ViewModel.绑定器.MVVM可以是单向绑定也可以是双向绑定甚至是不绑定 2) 绑定器: ...
- Python学习笔记:xlrd和xlwt(Excel读写)
xlrd模块 Python的三方库xlrd用于对excel文件进行读取,可以是“.xls”或“.xlsx”格式(旧版本可能不支持“.xlsx”). 下载安装:https://pypi.org/proj ...
- drf版本控制 django缓存
drf的版本控制 内置的版本控制类 from rest_framework.versioning import QueryParameterVersioning,AcceptHeaderVersion ...
- perl-basic-数组操作
RT...直接看代码 my @stack = ("Fred", "Eileen", "Denise", "Charlie" ...