CF830A/831D Office Keys

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF830A/831D Office Keys相关的知识,希望对你有一定的参考价值。

?????????namespace   i++   ??????   ??????   ??????   inf   style   stream   str   

?????????

????????????????????????????????????????????????????????????????????????n???????????????????????????????????????????????????

?????????

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <algorithm>
 5 using namespace std;
 6 typedef long long ll;
 7 const ll INF = 0x3f3f3f3f3f3f3f3f;
 8 ll man[1005], key[2005];
 9 ll cal(ll m, ll k, ll p)
10 {
11     if ((k >= m && k <= p) || (k <= m && k >= p)) return abs(m - p);
12     return abs(m - k) + abs(k - p);
13 }
14 int main()
15 {
16     ll n, k, p, ans = INF;
17     cin >> n >> k >> p;
18     for (int i = 0; i < n; i++) cin >> man[i];
19     for (int i = 0; i < k; i++) cin >> key[i];
20     sort(man, man + n); sort(key, key + k);
21     for (int i = 0; i <= k - n; i++)
22     {
23         ll maxn = 0;
24         for (int j = 0; j < n; j++)
25         {
26             maxn = max(maxn, cal(man[j], key[j + i], p));
27         }
28         ans = min(ans, maxn);
29     }
30     cout << ans << endl;
31     return 0;
32 }

 

以上是关于CF830A/831D Office Keys的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces 830A Office Keys

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

CF830CBamboo Partition 分块

#21 CF830D

Codeforces 830D Singer House 动态规划

CF830B:Cards Sorting