跳石头

题目背景

一年一度的“跳石头”比赛又要开始了!

题目描述

这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石。组委会已经选择好了两块岩石作为比赛起点和终点。在起点和终点之间,有 NN 块岩石(不含起点和终点的岩石)。在比赛过程中,选手们将从起点出发,每一步跳向相邻的岩石,直至到达终点。

为了提高比赛难度,组委会计划移走一些岩石,使得选手们在比赛过程中的最短跳跃距离尽可能长。由于预算限制,组委会至多从起点和终点之间移走 MM 块岩石(不能移走起点和终点的岩石)。

输入输出格式

输入格式:

第一行包含三个整数 L,N,ML,N,M,分别表示起点到终点的距离,起点和终点之间的岩石数,以及组委会至多移走的岩石数。保证 L \geq 1L≥1 且 N \geq M \geq 0N≥M≥0。

接下来 NN 行,每行一个整数,第 ii 行的整数 D_i( 0 < D_i < L)Di​(0<Di​<L), 表示第 ii 块岩石与起点的距离。这些岩石按与起点距离从小到大的顺序给出,且不会有两个岩石出现在同一个位置。

输出格式:

一个整数,即最短跳跃距离的最大值。

输入输出样例

输入样例#1: 复制

25 5 2
2
11
14
17
21
输出样例#1: 复制

4

说明

输入输出样例 1 说明:将与起点距离为 22和 1414 的两个岩石移走后,最短的跳跃距离为 44(从与起点距离 1717 的岩石跳到距离 2121 的岩石,或者从距离 2121 的岩石跳到终点)。

另:对于 20\%20%的数据,0 ≤ M ≤ N ≤ 100≤M≤N≤10。

对于50\%50%的数据,0 ≤ M ≤ N ≤ 1000≤M≤N≤100。

对于 100\%100%的数据,0 ≤ M ≤ N ≤ 50,000,1 ≤ L ≤ 1,000,000,0000≤M≤N≤50,000,1≤L≤1,000,000,000。

#include<bits/stdc++.h>
#define MAX 50005
using namespace std;
typedef long long ll; int a[MAX]; int main()
{
int t,i,j;
int L,N,M;
scanf("%d%d%d",&L,&N,&M);
a[]=;
for(i=;i<=N;i++){
scanf("%d",&a[i]);
}
a[N+]=L;
int l=,r=,m;
int ans=;
while(l<=r){
m=(l+r)/;
int pre=,cnt=;
for(i=;i<=N+;i++){
if(a[i]-a[pre]>=m){
pre=i;
cnt++;
} }
if(cnt>=N+-M){
ans=max(ans,m);
l=m+;
}
else{
r=m-;
}
}
printf("%d\n",ans);
return ;
}

跳石头(移除)

E

  • 61.05%
  • 2000ms
  • 262144K
 

5G5G is the proposed next telecommunications standards beyond the current 4G4G standards. 5G5G planning aims at higher capacity than current 4G4G, allowing a higher density of mobile broadband users, and supporting device-to- device, reliable, and massive wireless communications. AA telecommunication company would like to install more base stations to provide better communication for customers. Due to the installation cost and available locations, the company can only install S (2 \le S \le L)S(2≤S≤L) base stations at L (2 \le L \le 100, 000)L(2≤L≤100,000) candidate locations. Since the base stations work in the same frequency band, they will interfere and cause severe performance degradation. To provide high quality communication experience to customers, the company would like to maximize the distance between the base stations so as to reduce the wireless interference among the base stations. Suppose the L candidate locations are in a straight line at locations P_1, P_2, ... , PL (0 \le Pi \le 1, 000, 000)P1​,P2​,...,PL(0≤Pi≤1,000,000) and the company wants to install SS base stations at the LL candidate locations. What is the largest minimum distance among the SS base stations?

Input

The input data includes multiple test sets.

Each set starts with a line which specifies LL (i.e.i.e., the number of candidate locations) and SS (i.e.i.e., the number of base stations). The next line contains LL space-separated integers which represent P_1P1​ , P_2P2​ , ... , P_LPL​ . The input data ends “00 00”.

Output

For each set, you need to output a single line which should be the largest minimum distance among the base stations.

For the first set, the 33 base stations can be installed at locations 2, 6, 112,6,11.

样例输入复制

5 3
2 3 9 6 11
4 3
1 4 9 10
0 0

样例输出复制

4
3

题目来源

ACM-ICPC 2017 Asia HongKong

#include<bits/stdc++.h>
#define MAX 100005
using namespace std;
typedef long long ll; int a[MAX]; int main()
{
int t,i,j;
int n,s;
while(scanf("%d%d",&n,&s)&&n+s){
for(i=;i<=n;i++){
scanf("%d",&a[i]);
}
sort(a+,a+n+);
int l=,r=,m;
int ans=;
while(l<=r){
m=(l+r)/;
int pre=,cnt=;
for(i=;i<=n;i++){
if(a[i]-a[pre]>=m){
pre=i;
cnt++;
} }
if(cnt>=s){
ans=max(ans,m);
l=m+;
}
else{
r=m-;
}
}
printf("%d\n",ans);
}
return ;
}

E(选择)

NOIP2015提高组 跳石头 ACM-ICPC2017香港 E(选择/移除+二分答案)的更多相关文章

  1. 洛谷 P2678 & [NOIP2015提高组] 跳石头

    题目链接 https://www.luogu.org/problemnew/show/P2678 题目背景 一年一度的“跳石头”比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布 ...

  2. [NOIp2015提高组]跳石头

    OJ题号:洛谷2678 思路:贪心+二分. 从前往后扫,一旦这个石头到上一个选的石头的距离小于二分的值就把这块石头移走. #include<cstdio> #include<queu ...

  3. P2678 [NOIP2015 提高组] 跳石头

    #include<bits/stdc++.h> using namespace std; int l,n,m,a[100010];//与起点的距离 bool check(int d) { ...

  4. 【二分查找】 跳石头NOIP2015提高组 D2T1

    [二分查找]跳石头NOIP2015提高组 D2T1 >>>>题目 [题目描述] 一年一度的“跳石头”比赛又要开始了! 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石 ...

  5. 【题解】NOIP2015提高组 复赛

    [题解]NOIP2015提高组 复赛 传送门: 神奇的幻方 \([P2615]\) 信息传递 \([P2661]\) 斗地主 \([P2668]\) 跳石头 \([P2678]\) 子串 \([P26 ...

  6. 【数据结构】运输计划 NOIP2015提高组D2T3

    [数据结构]运输计划 NOIP2015提高组D2T3 >>>>题目 [题目描述] 公元 2044 年,人类进入了宇宙纪元.L 国有 n 个星球,还有 n−1 条双向航道,每条航 ...

  7. [NOIP2015 提高组] 运输计划题解

    题目链接:P2680 [NOIP2015 提高组] 运输计划 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 看了好长时间题解才终于懂的,有关lca和二分答案的题解解释的不详细,一时 ...

  8. [NOIP2015] 提高组 洛谷P2615 神奇的幻方

    题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...

  9. 洛谷-神奇的幻方-NOIP2015提高组复赛

    题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,--,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...

随机推荐

  1. 九度OJ 1027:欧拉回路 (欧拉回路)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2989 解决:1501 题目描述:     欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路.现给定一个图,问是 ...

  2. java中的clone方法

    Java中对象的创建 clone顾名思义就是复制, 在Java语言中, clone方法被对象调用,所以会复制对象.所谓的复制对象,首先要分配一个和源对象同样大小的空间,在这个空间中创建一个新的对象.那 ...

  3. weblogic开启远程访问的jmx设置

    通过jmx远程访问weblogic获取监控jvm的数据,要在weblogic启动的时候设置一些配置,具体如下: 在weblogic的安装目录:{weblogic_home}/wlserver_10.3 ...

  4. Java for LeetCode 093 Restore IP Addresses

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  5. swift和oc的混编

    一.Swift工程中加入oc代码 1.在将oc代码加入到Swift工程的时候Xcode会自动创建一个桥接文件“yourProgectName-Bridging-Header.h”,如果没有创建或者删除 ...

  6. [STM8L]基于STM8L152的TAB段式LCD液晶驱动的分析 - 单片机干货 - 中国电子技术论坛 - 最好最受欢迎电子论坛!

    [STM8L]基于STM8L152的TAB段式LCD液晶驱动的分析 - 单片机干货 - 中国电子技术论坛 - 最好最受欢迎电子论坛!.md 主控芯片为STM8L152C4T6自带LCD控制器,低功耗系 ...

  7. git设置只允许特定类型的文件

    git设置只允许特定类型的文件 # 忽略所有文件 * # 不忽略目录 !*/ # 不忽略文件.gitignore和*.foo !.gitignore !*.foo

  8. LightOJ - 1284 Lights inside 3D Grid —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1284 1284 - Lights inside 3D Grid    PDF (English) Statistic ...

  9. html5--2.5新的布局元素(4)-aside/nav

    html5--2.5新的布局元素(4)-aside/nav 学习要点 了解aside/nav元素的语义和用法 通过实例理解aside/nav元素的用法 aside元素(附属信息) aside元素通常用 ...

  10. 勤于思考:Objective-C特性的扩展

    赋值 assign:直接赋值.默认 @interface Car : NSObject { NSString *_name; } @property (assign,nonatomic) NSStri ...