Codeforces VK Cup Finals #424 Div.1 A. Office Keys(DP)
Posted Sakits
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces VK Cup Finals #424 Div.1 A. Office Keys(DP)相关的知识,希望对你有一定的参考价值。
显然是不可能交叉取钥匙的,于是把钥匙和人都按坐标排序就可以DP了
钥匙可以不被取,于是f[i][j]表示前i个钥匙被j个人拿的时间
f[i][j]=min(f[i-1][j],max(f[i-1][j-1],abs(b[i]-a[j])+abs(P-b[i]));
#include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=1010,inf=2e9; int n,k,p; int a[maxn],b[maxn*2],f[maxn*2][maxn]; void read(int &k) { int f=1;k=0;char c=getchar(); while(c<‘0‘||c>‘9‘)c==‘-‘&&(f=-1),c=getchar(); while(c<=‘9‘&&c>=‘0‘)k=k*10+c-‘0‘,c=getchar(); k*=f; } int main() { read(n);read(k);read(p); for(int i=1;i<=n;i++)read(a[i]); for(int i=1;i<=k;i++)read(b[i]); sort(a+1,a+1+n);sort(b+1,b+1+k); for(int i=1;i<=n;i++)f[0][i]=inf; for(int i=1;i<=k;i++) for(int j=1;j<=n;j++) f[i][j]=min(f[i-1][j],max(f[i-1][j-1],abs(b[i]-a[j])+abs(b[i]-p))); printf("%d\n",f[k][n]); return 0; }
以上是关于Codeforces VK Cup Finals #424 Div.1 A. Office Keys(DP)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答
Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Cards Sorting(树状数组)
Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B
Codeforces VK Cup Finals #424 Div.1 A. Office Keys(DP)
Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)
Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution 树状数组