CF830A Office Keys(贪心)
CF830A Office Keys
【题目链接】CF830A Office Keys
【题目类型】贪心
&题意:
有n个人,k个钥匙,一个目的地,求让n个人都回到目的地的最短时间,每个人都要拿钥匙才能回目的地
&题解:
这题做的时候没有认真想样例,如果仔细想的话就能发现n个人选的n个钥匙一定是连续的(在排过序之后),你可以这样想:
如果n个人直接去目的地,那么就肯定是连续的区间了吧,如果这个区间里钥匙数够,就可以直接回去了,如果不够,肯定是在区间的两边寻找剩下的钥匙,所以一定是连续的区间
&代码:
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define fo(i,a,b) for(int i=(a);i<=(b);i++)
#define fd(i,a,b) for(int i=(a);i>=(b);i--)
#define cle(a,v) memset(a,(v),sizeof(a))
const int maxn = 2e3 + 7;
int n, m, q;
int a[maxn], b[maxn];
int main() {
#ifndef ONLINE_JUDGE
freopen("E:1.in", "r", stdin);
#endif
scanf("%d%d%d", &n, &m, &q);
fo(i, 0, n - 1) scanf("%d", &a[i]);
fo(i, 0, m - 1) scanf("%d", &b[i]);
sort(b, b + m);
sort(a, a + n);
int ans = 0x7fffffff;
for(int i = 0; i <= m - n; i++) {
int ma = 0;
for(int j = 0; j < n; j++) {
ma = max(ma, abs(a[j] - b[i + j]) + abs(b[i + j] - q));
}
ans = min(ans, ma);
}
printf("%d\n", ans);
return 0;
}
CF830A Office Keys(贪心)的更多相关文章
- Codeforces 830A. Office Keys (贪心二分 or DP)
原题链接:http://codeforces.com/contest/830/problem/A 题意:在一条数轴上分别有n个人和k把钥匙(n<=k),以及一个目的地,每个人要各自拿到一个钥匙后 ...
- 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 ...
- CF830A/831D Office Keys
思路: 问题的关键在于对钥匙按照位置排序之后,最终选择的n个钥匙一定是其中的一个连续的区间. 实现: #include <iostream> #include <cstdio> ...
- 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 ...
- 【Codeforces Round #424 (Div. 2) D】Office Keys
[Link]:http://codeforces.com/contest/831/problem/D [Description] 有n个人,它们都要去一个终点,终点位于p; 但是,在去终点之前,他们都 ...
- CF-831D Office Keys 思维题
http://codeforces.com/contest/831/problem/D 题目大意是在一条坐标轴上,给出n个人,k把钥匙(k>=n)以及终点的坐标,所有人都可以同时运动,但不可以公 ...
随机推荐
- Boredom
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winte ...
- 使用控制台对Redis执行增删改查命令
使用控制台对Redis执行增删改查命令 在上一篇里,我们已经安装了redis.这一篇我们将一起来学习如何使用"控制台"管理Redis 首先肯定是打开一个控制台,在windows系统 ...
- webpack 打包测试和生产多个版本
cross-env修改生产环境变量 npm i --save-dev cross-env 在package.json里这么配置 npm run build就是打包到生产环境 npm run build ...
- C语言面对对象设计模式汇编
面向对象发展到今天,已经出现了许许多多优秀的实践.方法和技术.很多的技术都能够有效的提高软件质量.IBM上的<面向对象软件开发和过程>系列文章对面对对象设计从如下层面进行了详细的介绍:代码 ...
- Tarjan求割点(割顶) 割边(桥)
割点的定义: 感性理解,所谓割点就是在无向连通图中去掉这个点和所有和这个点有关的边之后,原先连通的块就会相互分离变成至少两个分离的连通块的点. 举个例子: 图中的4号点就是割点,因为去掉4号点和有关边 ...
- three.js 使用DragControls.js 拖动元素
首先,引入js文件: <script type="text/javascript" src="./path/to/DragControls.js"> ...
- java文件与流课后作业
1,编写一个程序,指定一个文件夹,能自动计算出其总容量, 2,编写一个文件加解密程序,通过命令行完成加解密工作3,编写一个文件分割工具,能把一个大文件分割成多个小的文件.并且能再次把它们合并起来得到完 ...
- Linux_相关命令(学习,备忘)
1.Linux 查看实时cpu使用率: top 说明:top命令即时显示process的动态 2.查看cpu处理器使用率: cat /proc/stat 3.平均cpu使用率 4.赋予文件夹下所有文件 ...
- python自动化打开网页
from selenium.webdriver.firefox.options import Options as FOptionsfrom selenium.webdriver.chrome.opt ...
- HDU 6321 Dynamic Graph Matching
HDU 6321 Dynamic Graph Matching (状压DP) Problem C. Dynamic Graph Matching Time Limit: 8000/4000 MS (J ...