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(贪心)的更多相关文章

  1. Codeforces 830A. Office Keys (贪心二分 or DP)

    原题链接:http://codeforces.com/contest/830/problem/A 题意:在一条数轴上分别有n个人和k把钥匙(n<=k),以及一个目的地,每个人要各自拿到一个钥匙后 ...

  2. Codeforces831D Office Keys

    D. Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  3. 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 ...

  4. 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 ...

  5. codeforce830A. Office Keys

    A. Office Keys time limit per test: 2 seconds memory limit per test: 256 megabytes input standard: i ...

  6. CF830A/831D Office Keys

    思路: 问题的关键在于对钥匙按照位置排序之后,最终选择的n个钥匙一定是其中的一个连续的区间. 实现: #include <iostream> #include <cstdio> ...

  7. 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 ...

  8. 【Codeforces Round #424 (Div. 2) D】Office Keys

    [Link]:http://codeforces.com/contest/831/problem/D [Description] 有n个人,它们都要去一个终点,终点位于p; 但是,在去终点之前,他们都 ...

  9. CF-831D Office Keys 思维题

    http://codeforces.com/contest/831/problem/D 题目大意是在一条坐标轴上,给出n个人,k把钥匙(k>=n)以及终点的坐标,所有人都可以同时运动,但不可以公 ...

随机推荐

  1. ionic2中使用极光IM的WebSDK实现即时聊天

    本文主要介绍如何在ionic项目中集成极光IM的WebSDK,详细文档可参考官方介绍. 一.准备 1. 注册激光账号,进入开发者服务页面创建应用. 2. 创建应用后须完成对应平台的推送设置,进行应用或 ...

  2. vue-video-player集成videojs-contrib-hls实现.m3u8文件播放

    // 安装依赖 npm install vue-video-player --save npm install videojs-contrib-hls --save // 在main.js中全局引入 ...

  3. Sorting It All Out (拓扑排序+floyd)

    An ascending sorted sequence of distinct values is one in which some form of a less-than operator is ...

  4. 关于postman各功能的说明及用法以及批量执行

    这玩意功能还不错,可以学学,在测试接口或者配合写代码测接口时是有帮助作用的.今天也去打听了一下,一下我就做了一下记录. 首先,主界面: 分开记录,写的详细一些. 左侧菜单栏: 主菜单(请求部分); 输 ...

  5. websocket-heartbeat-js心跳检测库正式发布

    前言: 两年前写了一篇websocket心跳的博客——初探和实现websocket心跳重连.  阅读量一直比较大,加上最近考虑写一个自己的npm包,因此就完成了一个websocket心跳的检测库.在这 ...

  6. Aragorn's Story HDU - 3966 -树剖模板

    HDU - 3966 思路 :树链剖分就是可以把一个路径上的点映射成几段连续的区间上.这样对于连续的区间可以用线段树维护, 对于每一段连续的区间都可以通过top [ ]数组很快的找到这段连续区间的头. ...

  7. Android-XML

    Android-XML XML文件: <?xml version="1.0" encoding="utf-8"?> <books> &l ...

  8. CSS---通向臃肿的道路(关于 “separation of concerns” (SoC)的原则)

    When it comes to CSS, I believe that the sacred principle of “separation of concerns” (SoC) has lead ...

  9. 用c# 开发html5的尝试,试用bridge.net

    Javascript交叉编译方案很多了,工业级品质的也不是没有,但前两年我从事html5 3d引擎开发时,做过一圈评估,没有可用的. 作为一个c#爱好者,我自然是很希望能最大限度的利用c#的生产力,之 ...

  10. Android的Activity组件

    本章主题是Activity组件:Activity是Android四大组价之一,其重要地位自然不用说.“Activity是应用程序中可见的交互组件的基类,大致上等同于传统桌面应用个程序开发中的窗体.”( ...