Codeforces 831 D Office Keys
2017-07-15 14:09
405 查看
题目地址:http://codeforces.com/contest/831/problem/D
题意: 办公室被锁住了,每个人必须去拿钥匙才能打开门,有n个人,m把钥匙,让你求出n个人全部进办公室的最短时间是多少。
思路:对人以及钥匙的位置进行排序,然后因为一定要去到办公室,所以说钥匙一定是连续的,因为最后都要去到办公室,那段距离想要竟可能短肯定是竟可能接近,所以遍历开始钥匙的起点再求n个人的区间,直接暴力就好了。
题意: 办公室被锁住了,每个人必须去拿钥匙才能打开门,有n个人,m把钥匙,让你求出n个人全部进办公室的最短时间是多少。
思路:对人以及钥匙的位置进行排序,然后因为一定要去到办公室,所以说钥匙一定是连续的,因为最后都要去到办公室,那段距离想要竟可能短肯定是竟可能接近,所以遍历开始钥匙的起点再求n个人的区间,直接暴力就好了。
#include <iostream> #include <cstring> #include <string> #include <queue> #include <vector> #include <map> #include <set> #include <stack> #include <cmath> #include <cstdio> #include <algorithm> #define LL long long #define N 2010 #define M 50010 #define inf 0x3f3f3f3f3f3f3f3f using namespace std; const LL mod = 1e9 + 7; const double eps = 1e-9; LL a , b ; int main() { cin.sync_with_stdio(false); int n, m, q; while (cin >> n >> m >> q) { for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } sort(a, a + n); sort(b, b + m); LL ans, sum; ans = inf; for (int i = 0; i <= m - n; i++) { sum = 0; for (int j = 0; j < n; j++) { sum = max(sum, abs(a[j] - b[j + i]) + abs(b[j + i] - q)); } ans = min(sum, ans); } cout << ans << endl; } return 0; }
相关文章推荐
- Codeforces - 831D. Office Keys - dp、二分+贪心
- codeforces 831 D Office Keys(dp)
- 【dp】codeforces 830-A Office Keys
- CodeForces 831 B.Keyboard Layouts(水~)
- Codeforces 831 C Jury Marks
- [CF831D] Office Keys(二分,贪心)
- 【Codeforces Round #424 (Div. 2) D】Office Keys
- Codeforces 831 A Unimodal Array
- CF Round #424( Div.2) D. Office Keys
- codeforces-702D-Road to Post Office
- CodeForces-702D Road to Post Office(初中数学脑洞题)
- Codeforces Round #424 -(二分&贪心)||dp-D. Office Keys
- Codeforces 831 B Keyboard Layouts
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Office Keys(思维)
- codeforces 702D D. Road to Post Office(数学)
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)D. Office Keys(二分+贪心)
- CF Round #424( Div.2) D. Office Keys 【二分||DP】
- Codeforces #831D: Office Keys 题解
- Codeforces Round #424 (Div. 2) Problem D. Office Keys
- Codeforces VK Cup Finals #424 Div.1 A. Office Keys(DP)