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个结果, ...
随机推荐
- 正向与反向拓扑排序的区别(hdu 1285 确定比赛名次和hdu 4857 逃生)
确定比赛名次 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- 对webdriver-driver句柄的理解
先贴代码: from selenium import webdriver //首先导入selenium(webdriver)相关模块 driver = webdriver.Firefox() ...
- Oracle语言环境变量配置
创建系统环境变量,以下为GBK和UTF8两种模式: 变量名:NLS_LANG变量值:SIMPLIFIED CHINESE_CHINA.ZHS16GBK 变量名:NLS_LANG变量值:SIMPLIFI ...
- 迁移virtualenv环境
记录一次将window上的virtualenv部署至LINUX服务器 前提 你已经使用virtualenv创建了一个虚拟的python运行环境,并且已经完成了你的应用的开发,现在需要将工程部署到服务器 ...
- 【CSS】面试知识整理
手写clearfix .clearfix:after { content: ''; display: table; clear: both; } .clearfix { *zoom:; } flex布 ...
- jmeter在几个固定的字符串中,随机取其中之一的方法
在测试过程中遇到上送字段必需是几个固定值中的一个, 使用读取文件中几个固定值,然后随机在这几个固定值中选择的办法解决问题 __CSVRead() CSV file to get values from ...
- php 守护进程(Daemon)
守护进程(daemon)是一类在后台运行的特殊进程,用于执行特定的系统任务. 很多守护进程在系统引导的时候启动,并且一直运行直到系统关闭. 守护进程一直在后台运行,脱离终端运行的程序 独立运行的守护进 ...
- 一个不错的多叉树, stl风格
tree<std::string> tr9; tree<std::string>::pre_order_iterator iter1; tr9.set_head("h ...
- 直接插入排序(js版)
直接插入排序(从小到大) 基本思想:将一个记录插入到已经排好序的有序表中,得到一个新的,记录数加1的有序表. function insertSort(arr){ var i,j,temp=0; for ...
- MySQL学习入门安装和启动及常见问题解决方法(一)
1.下载MySQL 官网地址:https://www.mysql.com/downloads/ 2.个人学习使用,只有下面这个是免费的 3.下载之后解压到目录中,并加入环境变量,如下 创建MYSQL_ ...