思路:

问题的关键在于对钥匙按照位置排序之后,最终选择的n个钥匙一定是其中的一个连续的区间。

实现:

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll man[], key[];
ll cal(ll m, ll k, ll p)
{
if ((k >= m && k <= p) || (k <= m && k >= p)) return abs(m - p);
return abs(m - k) + abs(k - p);
}
int main()
{
ll n, k, p, ans = INF;
cin >> n >> k >> p;
for (int i = ; i < n; i++) cin >> man[i];
for (int i = ; i < k; i++) cin >> key[i];
sort(man, man + n); sort(key, key + k);
for (int i = ; i <= k - n; i++)
{
ll maxn = ;
for (int j = ; j < n; j++)
{
maxn = max(maxn, cal(man[j], key[j + i], p));
}
ans = min(ans, maxn);
}
cout << ans << endl;
return ;
}

CF830A/831D Office Keys的更多相关文章

  1. CF830A Office Keys(贪心)

    CF830A Office Keys [题目链接]CF830A Office Keys [题目类型]贪心 &题意: 有n个人,k个钥匙,一个目的地,求让n个人都回到目的地的最短时间,每个人都要 ...

  2. Codeforces831D Office Keys

    D. Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) D. Office Keys time limit per test2 seconds 二分

    D. Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Office Keys(思维)

    Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  5. codeforce830A. Office Keys

    A. Office Keys time limit per test: 2 seconds memory limit per test: 256 megabytes input standard: i ...

  6. code force 424 A - Office Keys

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  7. CF-831D Office Keys 思维题

    http://codeforces.com/contest/831/problem/D 题目大意是在一条坐标轴上,给出n个人,k把钥匙(k>=n)以及终点的坐标,所有人都可以同时运动,但不可以公 ...

  8. AC日记——830A - Office Keys

    思路: 背包: 代码: #include <cmath> #include <cstdio> #include <cstring> #include <ios ...

  9. Codeforces VK Cup Finals #424 Div.1 A. Office Keys(DP)

    显然是不可能交叉取钥匙的,于是把钥匙和人都按坐标排序就可以DP了 钥匙可以不被取,于是f[i][j]表示前i个钥匙被j个人拿的时间 f[i][j]=min(f[i-1][j],max(f[i-1][j ...

随机推荐

  1. Ajax_数据格式_JSON

    [JSON] 1.JSON(JavaScript Object Notation)一种简单的数据格式,比xml更轻巧.JSON是JavaScript原生格式,这意味着在JavaScript中处理JSO ...

  2. codevs1226 倒水问题

    题目描述 Description 有两个无刻度标志的水壶,分别可装 x 升和 y 升 ( x,y 为整数且均不大于 100 )的水.设另有一水 缸,可用来向水壶灌水或接从水壶中倒出的水, 两水壶间,水 ...

  3. TortoiseGit推送失败的问题

    网络的SSH修改为使用git默认的ssh客户端,而不是tortosieGit提供的客户端 修改成这样 下面的本机凭证修改为当前用户 然后直接使用右键->git同步 在推送url上填写远程的url ...

  4. MySQL: 打开binlog选项后无法重启MySQL

    binlog目录权限不足导致,用chown mysql:mysql <log folder>即可解决此问题.

  5. 未来 Web 设计的 7 大趋势

    1.手势代替点击 还记得曾经是怎样滚动网页的吗?将鼠标移到屏幕的右边缘,然后拖动古代称为"滚动栏"的玩意儿: 略微专业点的可能会使用鼠标滚轮,光标键或触控板,这已经率先于大多数的用 ...

  6. 关于System.Convert那些事

    关于System.Convert那些事 前言 不知咋的,今天腰疼的不行,疼的站不起来了,今下午突然就疼起来了,唉,这是身体要垮了的节奏啊,再加上自己的VAX试用期到了,弄了半天也不行,烦. 正文 看到 ...

  7. 机器学习A

    订阅地址 :  http://blog.csdn.net/lizhe_dashuju/rss/list

  8. 李洪强经典面试题31- FMDB

    n什么是FMDB pFMDB是iOS平台的SQLite数据库框架 pFMDB以OC的方式封装了SQLite的C语言API p nFMDB的优点 p使用起来更加面向对象,省去了很多麻烦.冗余的C语言代码 ...

  9. HTTP的GET和POST请求

    1.GET请求: 格式例如以下: request-line headers blank-line request-body 如图是我用wireshark截的一个GET请求的HTTP首部: GET请求发 ...

  10. caffe代码阅读10:Caffe中卷积的实现细节(涉及到BaseConvolutionLayer、ConvolutionLayer、im2col等)-2016.4.3

    一. 卷积层的作用简单介绍 卷积层是深度神经网络中的一个重要的层,该层实现了局部感受野.通过这样的局部感受野,能够有效地减少參数的数目. 我们将结合caffe来解说详细是怎样实现卷积层的前传和反传的. ...