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 ...
随机推荐
- UVa - 12617 - How Lader
先上题目: How Lader Lader is a game that is played in a regular hexagonal board (all sides equal, all ...
- 0213微信ZABBIX报警
简介 微信作为日常使用最频繁的工具,因此希望将微信接入zabbix报警. 微信企业号 1.申请微信企业号 申请后,请在“我的企业”页面下记录企业号的CorpID 2.添加通讯录 部门添加完成后,根据实 ...
- Just a Hook 线段树 区间更新
Just a Hook In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of t ...
- The Pilots Brothers' refrigerator DFS+枚举
Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player ...
- PostGIS学习相关术语
POI 兴趣点(英语:point of interest,通常缩写成POI)乃是电子地图上的某个地标.景点,用以标示出该地所代表的政府部门.各行各业之商业机构(加油站.百货公司.超市.餐厅.酒店.便利 ...
- 查看表空间使用率及shrink 表空间
首先,可以通过下面的sql statement来查看表空间的使用情况.注意,该语句是在10g下测试过. SELECT FREE.TABLESPACE_NAME, FREE.FREE_SPACE/TOT ...
- Oracle基础(四)pl/sql
PL/SQL也是一种程序语言,叫做过程化SQL语言(Procedural Language/SQL). PL/SQL是Oracle数据库对SQL语句的扩展.在普通SQL语句的使用上添加了编程语言的特点 ...
- js 实现对ajax请求面向对象的封装
AJAX 是一种用于创建高速动态网页的技术.通过在后台与server进行少量数据交换.AJAX 能够使网页实现异步更新.这意味着能够在不又一次载入整个网页的情况下,对网页的某部分进行 ...
- easyUI中的layout
Layout 通过$.fn.layout.defaults能够重写Layout. layout是一个具有五个区域的容器.仅仅有中间区域面板是必须的,其余的都是边界面板.每个边界面板都能够通过拖动它的边 ...
- 七、备忘录模式Memento(行为型模式)
其目的是,在不违反封装原则的前提下.採集和备份一个对象的内部状态以便这个对象能够在以后恢复到之前的某个状态. 在Memento模式中,有例如以下角色: 1.Memento (备忘录) * 存储Orig ...