CF830A/831D Office Keys
思路:
问题的关键在于对钥匙按照位置排序之后,最终选择的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的更多相关文章
- CF830A Office Keys(贪心)
CF830A Office Keys [题目链接]CF830A Office Keys [题目类型]贪心 &题意: 有n个人,k个钥匙,一个目的地,求让n个人都回到目的地的最短时间,每个人都要 ...
- Codeforces831D Office Keys
D. Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 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 ...
- 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 ...
- codeforce830A. Office Keys
A. Office Keys time limit per test: 2 seconds memory limit per test: 256 megabytes input standard: i ...
- 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 ...
- CF-831D Office Keys 思维题
http://codeforces.com/contest/831/problem/D 题目大意是在一条坐标轴上,给出n个人,k把钥匙(k>=n)以及终点的坐标,所有人都可以同时运动,但不可以公 ...
- AC日记——830A - Office Keys
思路: 背包: 代码: #include <cmath> #include <cstdio> #include <cstring> #include <ios ...
- 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 ...
随机推荐
- [luoguP2285] [HNOI2004]打鼹鼠(DP)
传送门 设f[i]表示i个鼹鼠出现后,打死鼹鼠的最大值 动态转移方程:f[i]=max{f[j]+1}, 条件:abs(x[i]-x[j])+abs(y[i]-y[j])<=time[i]-ti ...
- Mybatis错误——Could not find parameter map java.util.Map
错误信息 org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map java.util.Ma ...
- Ubuntu 16.04安装uGet替代迅雷,并在Chrome中设置为默认下载器
uGet是采用aria2作为下载后端,所以两个软件都必须同时安装. 1.安装uGet sudo add-apt-repository ppa:plushuang-tw/uget-stable sudo ...
- PHP array_keys()
定义和用法 array_keys() 函数返回包含数组中所有键名的一个新数组. 如果提供了第二个参数,则只返回键值为该值的键名. 如果 strict 参数指定为 true,则 PHP 会使用全等比较 ...
- [学习笔记]JavaScript基础
JavaScript概述 1. JavaScript定义 JavaScript是Netscape公司开发的一种基于对象和事件驱动的脚本语言.它是弱类型语言.仅仅能由浏览器解释运行. 当中: 脚本语言: ...
- js上传文件
一.原始的XMLHttpRequestjs上传文件过程(參考地址:http://blog.sina.com.cn/s/blog_5d64f7e3010127ns.html) 用到两个对象 第一个对象: ...
- WinMain和MFC的差别
API(Application Programming Interface):开放给应用程序调用的系统功能. 一个Windows Application(SDK): WinMain ReristerC ...
- 关于C语言指针的一些新认识(2)
在使用C语言编程的过程中,遇到了很多关于指针使用的小问题,这里总结一下就当做是编程的小技巧啦 Q1. 如何用printf( )输出指针 这个问题相当于如何用printf( )输出地址,答案是:用"%p ...
- # [libx264 @ 00000275eb57fec0] height not divisible by 2 (520x325)
# [libx264 @ 00000275eb57fec0] height not divisible by 2 (520x325)
- qtree4
https://zybuluo.com/ysner/note/1236834 题面 给出一棵边带权的节点数量为\(n\)的树,初始树上所有节点都是白色.有两种操作: 改变节点\(x\)的颜色,即白变黑 ...