A. Office Keys ( Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) )
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int a[];
int b[];
int dp[][];
//dp[i][j] 前i个人从前j个药匙中到达终点的最小时间 int main()
{
int n,k,p;
while(~scanf("%d%d%d",&n,&k,&p))
{
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=k;i++) scanf("%d",&b[i]);
sort(a+,a++n);
sort(b+,b++k); for(int i=;i<=n;i++)
{
for(int j=i;j<=k;j++)
{
if(i==j)
{
dp[i][j]=max(dp[i-][j-],abs(p-b[j])+abs(a[i]-b[j]));
continue;
}
dp[i][j]=min(dp[i][j-],max(dp[i-][j-],abs(p-b[j])+abs(a[i]-b[j])));
}
} int ans = INT_MAX;
for(int i = n;i <= k;i++)
{
ans = min(ans,dp[n][i]);
}
printf("%d\n",ans);
}
return ;
}
A. Office Keys ( Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) )的更多相关文章
- 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 ...
- 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)
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) 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. 1, rated, based on VK Cup Finals) A. Office Keys
选择的钥匙一定是连续的,人和钥匙一定从左到右连续对应. 就枚举钥匙区间即可. #include<cstdio> #include<algorithm> using namesp ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Cards Sorting(树状数组)
Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 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 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 E (Codeforces 831E) - 线段树 - 树状数组
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...
随机推荐
- 阿里Java开发手册学习 3 MYSQL规约
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- myeclipse查看项目在本地的路径
打开myeclipse编译器,选择项目,右键:选择properties 在这一侧的搜索框中输入:resource Location即是项目的在本地的路径. 亲测好使.
- 编写灵活、稳定、高质量的 HTML 和 CSS 代码的规范。
引用地址http://codeguide.bootcss.com/#html-ie-compatibility-mode <!DOCTYPE html> <html lang=& ...
- AndroidSlideTest.java
以下代码使用ApiDemos-debug.apk进行测试 package com.saucelabs.appium; import io.appium.java_client.AppiumDriver ...
- poj3295 Tautology —— 构造法
题目链接:http://poj.org/problem?id=3295 题意: 输入由p.q.r.s.t.K.A.N.C.E共10个字母组成的逻辑表达式, 其中p.q.r.s.t的值为1(true)或 ...
- eclipse订制快捷键
步骤: 1.window-preference. 2.在(1)处输入keys,在(2)处输入命令的原来的快捷键,方便找到Binding,在(3)处输入自定义的快捷键.点击“apply and clos ...
- poj图论解题报告索引
最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman- ...
- 最小点覆盖 hdu--1054
点击打开题目链接 最小点覆盖=最大二分匹配的 (单向图) ; 最小点覆盖=最大二分匹配的一半 (双向图) ; 证明 所以我们只需求最大匹配,用 匈牙利算法 求出最大匹配,除以二得到答案 具体算法都已经 ...
- JAVA 需要理解的重点 一
需要理解的重点内容有: JVM内存管理机制和垃圾回收机制(基本每次面试都会问,一定要搞得透彻) JVM内存调优(了解是怎么回事,一般做项目过程中使用较多) 设计模式(熟悉常见设计模式的应用场景,会画类 ...
- ubuntu下网络性能测试
iperf的主要功能 TCP 测量网络带宽 报告MSS/MTU值的大小和观测值 支持TCP窗口值通过套接字缓冲 当P线程或Win32线程可用时,支持多线程.客户端与服务端支持同时多重连接 UDP 客户 ...