A. Office Keys (from Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) )

Posted jaydenouyang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A. Office Keys (from Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) )相关的知识,希望对你有一定的参考价值。

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 int a[150000];
 8 int b[150000];
 9 int dp[1005][1005];
10 //dp[i][j] 前i个人从前j个药匙中到达终点的最小时间
11 
12 int main()
13 {
14     int n,k,p;
15     while(~scanf("%d%d%d",&n,&k,&p))
16     {
17         memset(dp,0,sizeof(dp));
18         for(int i=1;i<=n;i++) scanf("%d",&a[i]);
19         for(int i=1;i<=k;i++) scanf("%d",&b[i]);
20         sort(a+1,a+1+n);
21         sort(b+1,b+1+k);
22 
23         for(int i=1;i<=n;i++)
24         {
25             for(int j=i;j<=k;j++)
26             {
27                 if(i==j)
28                 {
29                     dp[i][j]=max(dp[i-1][j-1],abs(p-b[j])+abs(a[i]-b[j]));
30                     continue;
31                 }
32                 dp[i][j]=min(dp[i][j-1],max(dp[i-1][j-1],abs(p-b[j])+abs(a[i]-b[j])));
33             }
34         }
35 
36         int ans = INT_MAX;
37         for(int i = n;i <= k;i++)
38         {
39             ans = min(ans,dp[n][i]);
40         }
41         printf("%d\n",ans);
42     }
43     return 0;
44 }

 

以上是关于A. Office Keys (from Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) )的主要内容,如果未能解决你的问题,请参考以下文章

office2007里的access数据库,怎么对2张表进行关联查询啊

CodeForces 830A Office Keys

AC日记——830A - Office Keys

CF830A/831D Office Keys

Codeforces 830A. Office Keys (背包dp+贪心) / (二分+贪心)

java CODE FESTIVAL 2017 qual B问题A.