Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals)
A
题意:给你人的坐标,钥匙的坐标,办公室的坐标。要求所有人能够拿到钥匙并且走到办公室的最短时间。一个位置只能有一个人,一个位置只有一把钥匙,人和钥匙可以在同一个位置。
思路:DP+贪心,dp[i]表示i这把钥匙被使用时人走的距离
代码:
#include<stdio.h>
#include<algorithm>
#include<string.h>
#define Inf 1e19;
#define ll long long
using namespace std;
int n,k;
ll p;
ll a[1100];
ll b[2200];
ll dp[2200];
int main()
{
while(~scanf("%d%d%I64d",&n,&k,&p))
{
for(int i=0; i<n; i++)
scanf("%I64d",&a[i]);
for(int i=0; i<k; i++)
scanf("%I64d",&b[i]);
sort(a,a+n);
sort(b,b+k);
ll ans=Inf;
memset(dp,0,sizeof(dp));
for(int i=0; i<k; i++)
{
if(i+n>k)
break;
for(int j=0; j<n; j++)
{
ll cnt=abs(b[i+j]-a[j])+abs(p-b[i+j]);
dp[i]=max(dp[i],cnt);
}
ans=min(ans,dp[i]);
}
printf("%I64d\n",ans);
}
return 0;
}
Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals)的更多相关文章
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)
http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)A,B,C
A:链接:http://codeforces.com/contest/831/problem/A 解题思路: 从前往后分别统计递增,相等,递减序列的长度,如果最后长度和原序列长度相等那么就输出yes: ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem A - B
Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is cons ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) A 水 B stl C stl D 暴力 E 树状数组
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - D
题目链接:http://codeforces.com/contest/831/problem/D 题意:在一个一维坐标里,有n个人,k把钥匙(钥匙出现的位置不会重复并且对应位置只有一把钥匙),和一个终 ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - C
题目链接:http://codeforces.com/contest/831/problem/C 题意:给定k个评委,n个中间结果. 假设参赛者初始分数为x,按顺序累加这k个评委的给分后得到k个结果, ...
随机推荐
- mysql与cmd,中文乱码
图中第一次select, 通过navicat插入表中的, 下面的这次select结果,是直接在命令行中插入的,中文就显示了两个问号...搞不懂咋回事..我是win10家庭版系统.....希望各位道友谨 ...
- 双硬盘,win10安装到固态盘
1.PE下格式化固态盘的系统盘 2.打开DG分区工具,查看固态盘的系统盘是否为激活状态,红色为激活,如果不是,激活一下 3.用windows安装器,或者hdd安装win10到固态盘 4.bios中启动 ...
- 摘选改善Python程序的91个建议
1.理解Pythonic概念 Pythonic Tim Peters 的 <The Zen of Python>相信学过 Python 的都耳熟能详,在交互式环境中输入import thi ...
- spring aop做什么介绍
1.AOP(Aspect Orient Programming),称为面向切面编程,它作为面向对象(OOP)的一种补充,用于处理系统中分布于各个模板的横切关注点,比如事务管理.日志.缓存等.AOP实现 ...
- 控制请求重复提交的方法总结(Token)
重复提交的定义: 重复提交指的是同一个请求(请求地址和请求参数都相同)在很短的时间内多次提交至服务器,从而对服务器造成不必要的资源浪费,甚至在代码不健壮的情况还会导致程序出错. 重复提交的原因或触发事 ...
- python json.dumps()函数输出json格式,使用indent参数对json数据格式化输出
在python中,要输出json格式,需要对json数据进行编码,要用到函数:json.dumps json.dumps() :是对数据进行编码 #coding=gbkimport json dict ...
- python 字符串 转 bit, bitarray 异或加密
Python中异或加密要将str 转为 bitarray, 提示: int类型和纯数字的字符串也可以异或处理, 可能更方便 from bitarray import bitarray def str2 ...
- vue中部分api解释 ($nextTick)
1:this.$nextTick(function(){ }) 传如的参数是一个函数 这个API主要是获取dom元素 为什么需要这个api,在vue框架开发中,更新dom是一个异步操作,如果更新完do ...
- sqlite基本用法
DDL-数据定义语言 CREATE 创建一个新的表,一个表的视图,或者数据库中的其他对象. ALTER 修改数据库中的某个已有的数据库对象,比如一个表. DROP 删除整个表,或者表的视图,或者数据库 ...
- cmd下的一些小技巧
切换盘符:[盘符]+: tips1: 在盘符A执行一条命令后的同时切换到盘符B:A:\>dir && B:(此处只能用&&或者&) tips2: 在盘符A ...