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栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...
随机推荐
- 12_1_Annotation注解
12_1_Annotation注解 1. 什么是注解 Annotation是从JDK5.0开始引入的新技术. Annotation的作用: 不是程序本身,可以对程序作出解释.可以被其他程序(比如,编译 ...
- node中的定时任务
node-schedule每次都是通过新建一个scheduleJob对象来执行具体方法. 时间数值按下表表示 * * * * * * ┬ ┬ ┬ ┬ ┬ ┬ │ │ │ │ │ | │ │ │ │ │ ...
- jQuery plugin : bgStretcher 背景图片切换效果插件
转自:http://blog.dvxj.com/pandola/jQuery_bgStretcher.html bgStretcher 2011 (Background Stretcher)是一个jQ ...
- Redis的安装、服务配置
在网上找了很多资料,有些可以正常安装,有些安装会出毛病,仔细想了想,还是自己整理一份吧,仅仅为自己下次再用的时候,能够快速的定位到可以正常用的文章! 我使用的是VMware Workstation P ...
- Decorator——Python初级函数装饰器
最近想整一整数据分析,在看一本关于数据分析的书中提到了(1)if __name__ == '__main__' (2)列表解析式 (3)装饰器. 先简单描述一下前两点,再详细解说Python初级的函数 ...
- GoF23种设计模式之行为型模式之模板方法
概述 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中. TemplateMethod使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 适用性 1.一次性实现一个算法的不变的部分, ...
- Linux操作系统启动流程
一般来说,所有的操作系统的启动流程基本就是: 总的来说,linux系统启动流程可以简单总结为以下几步:1)开机BIOS自检,加载硬盘.2)读取MBR,进行MBR引导.3)grub引导菜单(Boot L ...
- python 提交form-data之坑
#coding=utf-8 import requests from requests_toolbelt import MultipartEncoder #requests库上传 files = {& ...
- Python 实战一
列表ID的显示 起初ID显示的是数据库中的id,因为数据库中的id是自增长的,所以删除一条后,这里显示就叉开了,这里使用索引的方式来显示. 这个功能实现的逻辑: 第一:定义一个表格的架构,用id=‘i ...
- Mime类型与文件后缀对照表及探测文件MIME的方法
说明:刚刚写了一篇<IHttpHandler的妙用(2):防盗链!我的资源只有我的用户才能下载>的文章,网址:http://blog.csdn.net/zhoufoxcn/archive/ ...