AC日记——830A - Office Keys
思路:
背包;
代码:
#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的更多相关文章
- Codeforces 830A. Office Keys (贪心二分 or DP)
原题链接:http://codeforces.com/contest/830/problem/A 题意:在一条数轴上分别有n个人和k把钥匙(n<=k),以及一个目的地,每个人要各自拿到一个钥匙后 ...
- AC日记——codevs1688求逆序对
AC日记--codevs1688求逆序对 锵炬 掭约芴巷 枷锤霍蚣 蟠道初盛 到被他尽情地踩在脚下蹂躏心中就无比的兴奋他是怎么都 ㄥ|囿楣 定要将他剁成肉泥.挫骨扬灰跟随着戴爷这么多年刁梅生 圃鳋 ...
- 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 ...
- AC日记——Valued Keys codeforces 801B
801B - Valued Keys 思路: 水题... 来,上代码: #include <cstdio> #include <cstring> #include <io ...
- 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 ...
随机推荐
- MATLAB2010安装方法
MATLAB2010安装方法 第一步选择无网络安装. 选择yes,然后点击next 激活序列号在crack文件夹中的txt文档中 这一步按照图片上的显示操作就可以 选择经典安装 按提示操作,这一步事激 ...
- oracle、mysql、db2三大数据库分页方法的整理
最近项目中经常会涉及到代码中支持三种数据库的分页的功能,自己整理了关于三种数据库的分页的写法,分享给大家,以供大家使用.希望能帮到更多的码友! 先来看一个代码片段: String page = ala ...
- AI技术说:人工智能相关概念与发展简史
作为近几年的一大热词,人工智能一直是科技圈不可忽视的一大风口.随着智能硬件的迭代,智能家居产品逐步走进千家万户,语音识别.图像识别等AI相关技术也经历了阶梯式发展.如何看待人工智能的本质?人工智能的飞 ...
- Ubuntu 14.04.3 window10双系统情遇到'Disconnected: You are now offline'问题
笔电是win10系统,单独开除50G做了一个Ubuntu系统,安装的是14.04.03版本,安装成功后,发现wifi连接不上,选择wifi并输入密码后提示:“Disconnected: You are ...
- 洛谷P1124 文件压缩
https://www.luogu.org/problem/show?pid=1124 题目背景 提高文件的压缩率一直是人们追求的目标.近几年有人提出了这样一种算法,它虽然只是单纯地对文件进行重排,本 ...
- LightOJ 1166 Old Sorting 置换群 或 贪心 水题
LINK 题意:给出1~n数字的排列,求变为递增有序的最小交换次数 思路:水题.数据给的很小怎么搞都可以.由于坐标和数字都是1~n,所以我使用置换群求循环节个数和长度的方法. /** @Date : ...
- POJ 2318/2398 叉积性质
2318 2398 题意:给出n条线将一块区域分成n+1块空间,再给出m个点,询问这些点在哪个空间里. 思路:由于只要求相对位置关系,而对具体位置不关心,那么易使用叉积性质得到相对位置关系(左侧/右侧 ...
- ZOJ 3964 NIM变形
LINK 题意:n堆石子,Alice 和 Bob 轮流取石子,谁不能再取或被对方取完为败.但是对于alice拥有限制:b=0此堆正常无限制:b=1此堆Alice只能取奇数个石子:b=2只能取偶数个石子 ...
- Spring REST 异常处理
在上一篇中写到了Spring MVC的异常处理,SpringMVC捕获到异常之后会转到相应的错误页面,但是我们REST API ,一般只返回结果和状态码,比如发生异常,只向客户端返回一个500的状态码 ...
- 无聊,纯css写了个评分鼠标移入的效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...