思路:

问题的关键在于对钥匙按照位置排序之后,最终选择的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. SiteMesh基础教程

    SiteMesh是由一个基于Web页面布局.装饰以及与现存Web应用整合的框架.它能帮助我们在由大量页面构成的项目中创建一致的页面布局和外观,如一致的导航条,一致的banner,一致的版权,等等. 教 ...

  2. Mac: 通过蓝牙用安卓手机向Mac发送文件

    1. 打开Mac蓝牙和手机蓝牙 2. 配对 3. mac 系统偏好设置>共享 勾蓝牙共享,选接受并存储 4. 手机发送文件

  3. jQuery -&gt; 获取/设置HTML或TEXT内容

    jQuery提供了两个API能够直接用来为元素加入内容. html() text() 当中html()是为指定的元素加入html内容 text()是为指定的元素加入文本内容 两者的差别在于,text中 ...

  4. MYSQL利用Navicat对含有Bold字段表进行导入导出

    MYSQL中含有Blob字段是一件挺麻烦的事情,导出导入不方便.我介绍我是怎么做的. 1.在MYSQL的my.ini最后中加入一行配置max_allowed_packet = 100M,重新启动MYS ...

  5. 用WebCollector爬取新浪微博数据

    教程已转移:http://datahref.com/archives/28 WebCollector爬取新浪微博等完整演示样例project可加群250108697或345054141从群文件里下载. ...

  6. 负载均衡算法,轮询方式 大话设计模式之工厂模式 C#

    负载均衡算法,轮询方式 2018-04-13 17:37 by 天才卧龙, 13 阅读, 0 评论, 收藏, 编辑 学无止境,精益求精 十年河东,十年河西,莫欺少年穷 学历代表你的过去,能力代表你的现 ...

  7. LeetCode 680. Valid Palindrome II (验证回文字符串 Ⅱ)

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...

  8. iOS开发-植入广告(iAd, Admob实例)

    应用中植入广告是一种非常好的盈利手段. 以下介绍主流的两种方法.iAd, Admob 先mark一个非常具体的pdf.   http://pan.baidu.com/share/link?sharei ...

  9. cocos2d-x 3.0 常见问题及解决

    我自己遇到的问题记录,会及时更新.希望对大家有帮助 1.打包图片生成plist后,假设在游戏中图片挨在一起可能会出现黑线,打包时将Extrude设为1就可以 2.Xcode环境下.更新资源后执行的时候 ...

  10. Silverlight 2学习笔记一:初识Silverlight

    Silverlight,问世至今已有好一段时日了,向来只是只闻其名,不知其实,今天终于对Silverlight有了点初步的了解. 一.Silverlight是什么?Sliverlight是基于.NET ...