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. iOS快速开发框架--Bee Framework

    Bee Framework是一款iOS快速开发框架,允许开发者使用Objective-C和XML/CSS来进行iPhone和iPad开发,由 Gavin Kwoe 和 QFish 开发并维护. 其早期 ...

  2. IOS中将颜色转换为image

    - (UIImage *)createImageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f ...

  3. 【MySql】Mysql ERROR 1067: Invalid default value for ‘date’ 解决

    在给一个表添加字段的时候,忽然发现会报一个date类型的字段的默认值错误,郁闷~ 经过排查,原来是MySQL的配置问题,在wamp下,MySQL 5.7里是没有设置 SQL_MODE 的. 1.my. ...

  4. vue-cli3.0相关的坑

    vue-cli3.0相对比vue-cli2.0少了 vue-build.js vue-config.js vue-cli2.0 运行命令 npm run devvue-cli3.0 运行命令 npm ...

  5. destoon模块自定义字段的添加并让其支持搜索的方法

    今天看了看模块设置里的自定义字段功能的用法,试着加了个新字段glry,设置了值,然后去数据库moduleid的article表看,字段成功加上了. 于是去template下article文件夹的lis ...

  6. Python使用gevent实现协程

    Python中多任务的实现可以使用进程和线程,也可以使用协程. 一.协程介绍 协程,又称微线程.英文名Coroutine.协程是Python语言中所特有的,在其他语言中没有. 协程是python中另外 ...

  7. CUB reduce errorinvalid configuration argument

    解决CUB reduce errorinvalid configuration argument问题 在写TensorFlow代码时遇到报错 CUB reduce errorinvalid confi ...

  8. i2c_drivers个人分析

    \arch\arm\mach-mx6\board-mx6q_sabresd.c static struct i2c_board_info i2c_board_info_rtc[] __initdata ...

  9. 稀疏表(ST / Sparse Table)

    RMQ问题: 给定一个序列,每次询问一个区间最小值 / 最大值. 没有修改. //拿区间最大值来举例. memset(ans, -INF, sizeof(ans)); for (int i = 1; ...

  10. SSAS——MDX基础

    一.基本概念 MDX:一种查询语言,从多维的数据集单元格中检索数据.支持两种不同的模式: 1.表达式语言:定义和操纵Analysis Services对象和数据以计算值 2.查询语言:从Analysi ...