Problem B. Travelling Camera Problem

题目连接:

http://www.codeforces.com/gym/100253

Description

Programming competitions become very popular in Berland. Now Berland Broadcasting Corporation

(BBC) plans to organize a TV broadcast of the All-Berland Regional Contest. The contest will be in a

narrow hall stretched from the left to the right. BBC puts a long straight rail with a camera on it along

the hall. The rail starts from the left wall and goes along the hall to the right wall.

Not every position of the camera on the rail is suitable for shooting. The cameraman has chosen m

shooting positions on the rail: c1, c2, . . . , cm, where ci

is the distance (in meters) from the i-th position to

the left wall. Initially the camera will be at the position c1.

The reporter has prepared the plan showing how she will move tomorrow. She will move only along a

line parallel to the rail on the distance 1 meter from the rail. So each her position is dened by a single

number x the distance (in meters) from the left wall.

The coverage will consist of n scenes. The rst scene will be at the position x1, so the reporter will start

the live coverage there. The second scene will be at the position x2, so she will move from x1 to x2 between

the scenes. The third scene will be at the position x3 and so on. In total the reporter will successively

visit n positions x1, x2, . . . , xn, the j-th scene will be at xj .

For sure it is a bad idea to shoot the reporter if she is too far from the camera. It should be at most r

meters to the reporter at the moments of scenes.

Write a program to nd the minimum total distance the camera will move tomorrow. You may assume

that both the camera and the reporter move only along their lines, the maximum speed of the camera is

enough to keep up with the reporter.

Input

The rst line of the input contains three integer numbers m (2 ≤ m ≤ 3 · 105

), n (2 ≤ n ≤ 3 · 105

), r

(1 ≤ r ≤ 1000), where m is the number of positions where the camera can shoot, n is the number of

scenes and r is the maximum distance between the camera and the reporter in the moments of scenes.

The second line contains valid camera positions: m real numbers c1, c2, . . . , cm (0 ≤ ci ≤ 106

). The

numbers are given with exactly one digit after the decimal point. They are given in the strictly increasing

order (ci < ci+1 for each 1 ≤ i < m).

The third line contains positions of scenes in the chronological order: n real numbers x1, x2, . . . , xn

(0 ≤ xj ≤ 106

). The numbers are given with exactly one digit after the decimal point. These numbers are

not necessarily distinct.

It is guaranteed that it is possible to nd at least one valid camera position for each scene

Output

Print a single real number with at least one digit after the decimal point the minimum total distance

the camera needs to move to shoot all the scenes.

Sample Input

4 3 4

10.0 20.0 30.0 40.0

31.0 41.0 20.0

Sample Output

50.0

Hint

题意

给你摄像头的坐标,给你人依次所在的位置,你摄像头能够照到这个人的条件是,你们俩的坐标距离相差小于等于k

问你摄像头最少走多少米

题解:

对于每个人,可以划分出一个区间来,然后贪心的走最少的路程到达这个区间就好了。

代码

#include<bits/stdc++.h>
using namespace std; int n,m;
double k;
set<double>S;
int main()
{
scanf("%d%d%lf",&n,&m,&k);
double now;
for(int i=1;i<=n;i++)
{
double x;
cin>>x;
if(i==1)now=x;
S.insert(x);
}
double ans = 0;
double len = sqrt(k*k-1);
for(int i=1;i<=m;i++)
{
double x;
cin>>x;
if(x+len>=now&&x-len<=now)continue;
double L = *S.lower_bound(x-len);
double R = *--S.upper_bound(x+len);
if(abs(L-now)<abs(R-now))
{
ans+=abs(L-now);
now=L;
}
else
{
ans+=abs(R-now);
now=R;
}
}
printf("%.12f\n",ans);
}

2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem B. Travelling Camera Problem set贪心的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  4. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  5. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  7. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  9. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

  10. 2018-2019 ICPC, NEERC, Southern Subregional Contest (codeforces 1070)

    A. 直接从状态(0,0)bfs, 这样一定是最小的 #include <iostream> #include <sstream> #include <algorithm ...

随机推荐

  1. ASP.NET MVC学习(五)之MVC原理解析

    ASP.NET MVC 请求生命周期 生命周期步骤概览 当我们对ASP.NET MVC网站发出一个请求的时候,会发生5个主要步骤: 步骤1:创建RouteTable 当ASP.NET应用程序第一次启动 ...

  2. Mogodb 学习一

    0.MongoDB和关系型数据的几个重要对象对比 MongoDB中的数据库.集合.文档 类似于关系型数据库中的数据库.表.行 MongoDB中的集合是没有模式的,所以可以存储各种各样的文档 1.启动M ...

  3. CSS规范 - 命名规则--(来自网易)

    使用类选择器,放弃ID选择器 ID在一个页面中的唯一性导致了如果以ID为选择器来写CSS,就无法重用. NEC特殊字符:"-"连字符 "-"在本规范中并不表示连 ...

  4. mybatis介绍——(一)

    官方API:http://www.mybatis.org/mybatis-3/index.html 中文: http://www.mybatis.org/mybatis-3/zh/index.html ...

  5. 因子分析(Factor analysis)

    1.引言 在高斯混合和EM算法中,我们运用EM算法拟合混合模型,但是我们得考虑得需要多少的样本数据才能准确识别出数据中的多个高斯模型!看下面两种情况的分析: 第一种情况假如有 m 个样本,每个样本的维 ...

  6. mysql学习------二进制日志管理

    MySQL二进制日志(Binary Log)   a.它包含的内容及作用如下:    包含了所有更新了数据或者已经潜在更新了数据(比如没有匹配任何行的一个DELETE)    包含关于每个更新数据库( ...

  7. Shell脚本实现非法IP登陆自动报警【转】

    服务器的安全稳定是每个运维都希望达到的目标,毕竟网站一旦流量大了,访问高了,就会有一些无聊人来攻击,帮忙检测漏洞是好,但纯ddos的性质就很恶劣了.说远了,这篇文章只是检测有非法ip登录到服务器上就自 ...

  8. mysql 字符编码设置

    安装mysql时如果字符编码为默认值latin1,则需要修改为utf8以便支持中文数据. 命令如下: 1.显示数据库字符集 mysql> show create database test;+- ...

  9. 报错stale element reference: element is not attached to the page document结局方案

    今天在调试脚本时,遇到如下报错: org.openqa.selenium.StaleElementReferenceException: stale element reference: elemen ...

  10. 使用android模拟器开发程序

    自从android studio升级到3.0之后自带的模拟器已经很好用了,尤其是升级后可以想vmware那样休眠,再次开启就可以快速启动了 以下是几点可以更方便地使用系统模拟器进行开发的小技巧,毕竟模 ...