思路:

  背包;

代码:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 1005
#define maxk 2005
#define ll long long
int n,k,p;
ll dp[maxn][maxk],ai[maxn],bi[maxk];
inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
inline void in(ll &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
inline ll check()
{
//memset(dp,127/3,sizeof(dp));
for(int i=;i<=n;i++)
for(int v=;v<=k;v++)
dp[i][v]=max(dp[i-][v-],abs(ai[i]-bi[v])+abs(bi[v]-p));
ll Min=2e9;
for(int i=n;i<=k;i++) Min=min(dp[n][i],Min);
return Min;
}
int main()
{
in(n),in(k),in(p);
for(int i=;i<=n;i++) in(ai[i]);
for(int i=;i<=k;i++) in(bi[i]);
sort(ai+,ai+n+),sort(bi+,bi+k+);
cout<<check();
return ;
}

AC日记——830A - Office Keys的更多相关文章

  1. Codeforces 830A. Office Keys (贪心二分 or DP)

    原题链接:http://codeforces.com/contest/830/problem/A 题意:在一条数轴上分别有n个人和k把钥匙(n<=k),以及一个目的地,每个人要各自拿到一个钥匙后 ...

  2. AC日记——codevs1688求逆序对

    AC日记--codevs1688求逆序对 锵炬 掭约芴巷 枷锤霍蚣 蟠道初盛 到被他尽情地踩在脚下蹂躏心中就无比的兴奋他是怎么都 ㄥ|囿楣 定要将他剁成肉泥.挫骨扬灰跟随着戴爷这么多年刁梅生 圃鳋 ...

  3. CF830A Office Keys(贪心)

    CF830A Office Keys [题目链接]CF830A Office Keys [题目类型]贪心 &题意: 有n个人,k个钥匙,一个目的地,求让n个人都回到目的地的最短时间,每个人都要 ...

  4. Codeforces831D Office Keys

    D. Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  5. 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 ...

  6. 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 ...

  7. codeforce830A. Office Keys

    A. Office Keys time limit per test: 2 seconds memory limit per test: 256 megabytes input standard: i ...

  8. AC日记——Valued Keys codeforces 801B

    801B - Valued Keys 思路: 水题... 来,上代码: #include <cstdio> #include <cstring> #include <io ...

  9. 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 ...

随机推荐

  1. mysql数据库----下载安装、操作

    一.mysql概述 1.什么是数据库 ? 答:数据的仓库,如:在ATM的示例中我们创建了一个 db 目录,称其为数据库 2.什么是 MySQL.Oracle.SQLite.Access.MS SQL ...

  2. 《剑指offer》— JavaScript(12)数值的整数次方

    数值的整数次方 题目描述 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 思路一 考察指数的正负以及底数是否为零的几种情形: 将指数转换 ...

  3. mac 的全文搜索

    grep -Rni "view.proptypes.style" *  需要切换到要搜索的目录在运行

  4. libevent学习笔记(参考libevent深度剖析)

    最近自学libevent事件驱动库,参考的资料为libevent2.2版本以及张亮提供的<Libevent源码深度剖析>, 参考资料: http://blog.csdn.net/spark ...

  5. opencv函数制作的时钟模型

    http://www.cnblogs.com/sytu/p/4192652.html 在秒针模型的基础上添加了分针和时针,并且添加了暂停控件和设置时间的功能. #include"cv.h&q ...

  6. C++ ------ 互斥锁、原子操作的性能测试

    atomic原子操作:是在新标准C++11,引入了原子操作的概念,并通过这个新的头文件提供了多种原子操作数据类型,例如,atomic_bool,atomic_int等等 测试程序 #include & ...

  7. C#实现SQL数据库备份与恢复

    有两种方法,都是保存为.bak文件.一种是直接用Sql语句执行,另一种是通过引用SQL Server的SQLDMO组件来实现:  1.通过执行Sql语句来实现 注意,用Sql语句实现备份与还原操作时, ...

  8. (转) 使用vivado创建工程 3

    Create a Hello World application In this experiment we will use Xilinx SDK to create a simple Hello ...

  9. net-speeder

    有的同学反映自己的搬瓦工速度慢,丢包率高.这其实和你的网络服务提供商有关.据我所知一部分上海电信的同学就有这种问题.那么碰到了坑爹的网络服务商,我们应该怎么办呢? duangduang~~~~~~有请 ...

  10. 在eclipse安装mybatis的插件

    1.在help中打开 2.搜索mybatipse 3:功能简介 1:要查找某一个方法        在dao接口中某一个方法中 按住 Ctrl键 鼠标指到方法名称上 选择open xml 就会自动跳转 ...