Messenger

【问题描述】

alice和bob各自在两条折线上行进,一个邮递员要从alice那拿一个包裹,并以直线移动到bob处,alice和bob、邮递员的速度均为1单位/s,问邮递员最少要走多少秒才能送完包裹。

【输入格式】

输入数据的第一行是一个整数na,代表alice运动轨迹的折线上的顶点数。
之后na行,每行两个整数,依次代表这个折线的第1号点、第2号点......第na号点的坐标。
之后一行是一个整数nb,代表bob运动轨迹的折线上的顶点数。
之后nb行,每行两个整数,依次代表这个折线的第1号点、第2号点......第nb号点的坐标。
na,nb目测是50000以内

【输出格式】

输出只有一行,一个小数,代表邮递员最少要走的时间。若无解,输出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的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. BZOJ 2127: happiness [最小割]

    2127: happiness Time Limit: 51 Sec  Memory Limit: 259 MBSubmit: 1815  Solved: 878[Submit][Status][Di ...

  3. android:使用Messenger进行进程间通信(一)

    Messenger简介 Messenger和AIDL是实现进程间通信(interprocess communication)的两种方式. 实际上,Messenger的实现其实是对AIDL的封装. Me ...

  4. BZOJ 3275: Number

    3275: Number Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 874  Solved: 371[Submit][Status][Discus ...

  5. BZOJ 2879: [Noi2012]美食节

    2879: [Noi2012]美食节 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1834  Solved: 969[Submit][Status] ...

  6. bzoj 4610 Ceiling Functi

    bzoj 4610 Ceiling Functi Description bzoj上的描述有问题 给出\(n\)个长度为\(k\)的数列,将每个数列构成一个二叉搜索树,问有多少颗形态不同的树. Inp ...

  7. BZOJ 题目整理

    bzoj 500题纪念 总结一发题目吧,挑几道题整理一下,(方便拖板子) 1039:每条线段与前一条线段之间的长度的比例和夹角不会因平移.旋转.放缩而改变,所以将每条轨迹改为比例和夹角的序列,复制一份 ...

  8. 【sdoi2013】森林 BZOJ 3123

    Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M,T,分别表示节点数.初始边数.操作数.第三行包含N个非负整数 ...

  9. 【清华集训】楼房重建 BZOJ 2957

    Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...

随机推荐

  1. Spring3中好用的工具类收集

    1) 请求工具类 org.springframework.web.bind.ServletRequestUtils //取请求参数的整数值: public static Integer getIntP ...

  2. 约束Constraints

    1.setNeedsUpdateConstraints:当想要调整子视图布局时,在主线程调用该方法标记constraint需要在未来的某个点更新(该方法不会立刻强制刷新constraint,而是等待下 ...

  3. 27. Remove Element@python

    Given an array nums and a value val, remove all instances of that value in-place and return the new ...

  4. ubuntu 16.04 +anaconda3.6 +Nvidia DRIVER 390.77 +CUDA9.0 +cudnn7.0.4+tensorflow1.5.0+neural-style

    这是我第一个人工智能实验.虽然原理不是很懂,但是觉得深度学习真的很有趣.教程如下. Table of Contents 配置 时间轴 前期准备工作 anaconda3 安装 bug 1:conda:未 ...

  5. MATLAB编程技巧

    [摘要] MATLAB是一种科学计算语言,和C.Fortran等高级语言相类似,能方便的实现程序控制.以下介绍一点matlab编程的技巧. 嵌套计算 程序执行的速度取决于调用的子程序的个数和算法实现. ...

  6. HashMap与ArrayMap(和SparseArray)的比较与选择

    HashMap与ArrayMap(和SparseArray)的比较与选择 2017年12月26日 06:04:38 阅读数:61 标签: androidjavahashmaparraymap数据结构 ...

  7. Pandas中数据的处理

    有两种丢失数据 ——None ——np.nan(NaN) None是python自带的,其类型为python object.因此,None不能参与到任何计算中 Object类型的运算比int类型的运算 ...

  8. 【android】安卓平台版本和API版本的对应关系

    安卓平台版本和API版本对应关系

  9. jQuery获取动态添加的元素,live和on的区别

    今天给大家说一下如果用jQuery获取动态添加的元素,通常如果你在网页上利用jQuery添加一个元素,那么用平常的jQuery获取元素的方法无效的获取不到的.可以用以下的方法获取动态元素!假设我们现在 ...

  10. 什么是python中的元类

    所属网站分类: python高级 > 面向对象 作者:goodbody 原文链接: http://www.pythonheidong.com/blog/article/11/ 来源:python ...