链接:

https://ac.nowcoder.com/acm/contest/918/I

题意:

一场别开生面的牛吃草大会就要在Farmer John的农场举办了!

世界各地的奶牛将会到达当地的机场,前来参会并且吃草。具体地说,有N头奶牛到达了机场(1≤N≤105),其中奶牛i在时间ti(0≤ti≤109)到达。Farmer John安排了M(1≤M≤10^5)辆大巴来机场接这些奶牛。每辆大巴可以乘坐C头奶牛(1≤C≤N)。Farmer John正在机场等待奶牛们到来,并且准备安排到达的奶牛们乘坐大巴。当最后一头乘坐某辆大巴的奶牛到达的时候,这辆大巴就可以发车了。Farmer John想要做一个优秀的主办者,所以并不想让奶牛们在机场等待过长的时间。如果Farmer John合理地协调这些大巴,等待时间最长的奶牛等待的时间的最小值是多少?一头奶牛的等待时间等于她的到达时间与她乘坐的大巴的发车时间之差。

输入保证MC≥N。

思路:

二分答案

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t; int Times[MAXN]; bool Check(int x)
{
int he = 1, now = 1;
for (int c = 1;c <= m;c++)
{
while (now <= n && now-he+1 <= k && Times[now]-Times[he] <= x)
now++;
he = now;
}
if (he > n)
return true;
return false;
} int main()
{
scanf("%d%d%d", &n, &m, &k);
for (int i = 1;i <= n;i++)
scanf("%d", &Times[i]);
sort(Times+1, Times+1+n);
int l = 0, r = Times[n];
int res = 1e9;
while (l<r)
{
// cout << l << ' ' << r << endl;
int mid = (l+r)/2;
if (Check(mid))
{
res = min(res, mid);
r = mid;
}
else
l = mid+1;
}
cout << res << endl; return 0;
}

牛客假日团队赛1 I.接机的更多相关文章

  1. 牛客假日团队赛10 L 乘积最大 (dp,大数)

    链接:https://ac.nowcoder.com/acm/contest/1072/L?&headNav=acm&headNav=acm 来源:牛客网 乘积最大 时间限制:C/C+ ...

  2. P5200 [USACO19JAN]Sleepy Cow Sorting 牛客假日团队赛6 D 迷路的牛 (贪心)

    链接:https://ac.nowcoder.com/acm/contest/993/E 来源:牛客网 对牛排序 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...

  3. 牛客假日团队赛6 D 迷路的牛 (思维)

    链接:https://ac.nowcoder.com/acm/contest/993/D 来源:牛客网 迷路的牛 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...

  4. 牛客假日团队赛5J 护城河 bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包的周长)

    链接:https://ac.nowcoder.com/acm/contest/984/J 来源:牛客网 护城河 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...

  5. 牛客假日团队赛5 K 金币馅饼 (DP 基础题)

    链接:https://ac.nowcoder.com/acm/contest/984/K 来源:牛客网 金币馅饼 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...

  6. 牛客假日团队赛5 L Catch That Cow HDU 2717 (BFS)

    链接:https://ac.nowcoder.com/acm/contest/984/L 来源:牛客网 Catch That Cow 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 3 ...

  7. 牛客假日团队赛5 F 随机数 BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 (dfs记忆化搜索的数位DP)

    链接:https://ac.nowcoder.com/acm/contest/984/F 来源:牛客网 随机数 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...

  8. 洛谷 P2866 [USACO06NOV]糟糕的一天Bad Hair Day 牛客假日团队赛5 A (单调栈)

    链接:https://ac.nowcoder.com/acm/contest/984/A 来源:牛客网 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,00 ...

  9. 「BZOJ1669」D 饥饿的牛 [Usaco2006 Oct] Hungry Cows 牛客假日团队赛5 (LIS,离散化树状数组)

    链接:https://ac.nowcoder.com/acm/contest/984/D 来源:牛客网 饥饿的牛 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...

随机推荐

  1. debian上安装codeblocks

    1.查看linux的版本uname -a 2.在官网上下载稳定版的codeblocks(www.codeblocks.org) 3.解压codeblocks后,进入到文件夹中用root身份执行dpkg ...

  2. virtual judge(专题一 简单搜索 C)

    Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...

  3. spark提交模式

    spark基本的提交语句: ./bin/spark-submit \ --class <main-class> \ --master <master-url> \ --depl ...

  4. QTP连接数据库

    '注意:其中DSN=数据源名:UID=用户名:PWD=用户密码 Dim Conn Set Conn=CreateObject("ADODB.Connection") Const C ...

  5. k8s组件简介

    Kubernetes is constructed using several components, as follows:f Kubernetes masterf Kubernetes nodes ...

  6. 使用union来遍历结构体中的成员

    前几天和实验室的同学讨论问题的时候发现他使用的一段数据校验的代码自己以前没有接触过,今天有空就把它整理了一下. #include <stdio.h> #include <stdlib ...

  7. iOS使用VideoToolbox硬编码录制H264视频

    http://blog.csdn.net/shawnkong/article/details/52045894

  8. 利用Ssocks访问国外网站(yutube/google等)

    ***开源项目:https://github.com/***/ 本例使用的是针对windows系统的c-sharp版本:https://github.com/***/***-windows 运行*** ...

  9. SpringSecurity02 表单登录、SpringSecurity配置类

    1 功能需求 springSecuriy默认的登录窗口是一个弹出窗口,而且会默认对所有的请求都进行拦截:要求更改登录页面(使用表单登录).排除掉一些请求的拦截 2 编写一个springSecurity ...

  10. MQTT协议实现Eclipse Paho学习总结二

    一.概述 前一篇博客(MQTT协议实现Eclipse Paho学习总结一) 写了一些MQTT协议相关的一些概述和其实现Eclipse Paho的报文类别,同时对心跳包进行了分析.这篇文章,在不涉及MQ ...