NOIP2015提高组 跳石头 ACM-ICPC2017香港 E(选择/移除+二分答案)
跳石头
题目背景
一年一度的“跳石头”比赛又要开始了!
题目描述
这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石。组委会已经选择好了两块岩石作为比赛起点和终点。在起点和终点之间,有 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 说明:将与起点距离为 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
题目来源
#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(选择/移除+二分答案)的更多相关文章
- 洛谷 P2678 & [NOIP2015提高组] 跳石头
题目链接 https://www.luogu.org/problemnew/show/P2678 题目背景 一年一度的“跳石头”比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布 ...
- [NOIp2015提高组]跳石头
OJ题号:洛谷2678 思路:贪心+二分. 从前往后扫,一旦这个石头到上一个选的石头的距离小于二分的值就把这块石头移走. #include<cstdio> #include<queu ...
- P2678 [NOIP2015 提高组] 跳石头
#include<bits/stdc++.h> using namespace std; int l,n,m,a[100010];//与起点的距离 bool check(int d) { ...
- 【二分查找】 跳石头NOIP2015提高组 D2T1
[二分查找]跳石头NOIP2015提高组 D2T1 >>>>题目 [题目描述] 一年一度的“跳石头”比赛又要开始了! 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石 ...
- 【题解】NOIP2015提高组 复赛
[题解]NOIP2015提高组 复赛 传送门: 神奇的幻方 \([P2615]\) 信息传递 \([P2661]\) 斗地主 \([P2668]\) 跳石头 \([P2678]\) 子串 \([P26 ...
- 【数据结构】运输计划 NOIP2015提高组D2T3
[数据结构]运输计划 NOIP2015提高组D2T3 >>>>题目 [题目描述] 公元 2044 年,人类进入了宇宙纪元.L 国有 n 个星球,还有 n−1 条双向航道,每条航 ...
- [NOIP2015 提高组] 运输计划题解
题目链接:P2680 [NOIP2015 提高组] 运输计划 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 看了好长时间题解才终于懂的,有关lca和二分答案的题解解释的不详细,一时 ...
- [NOIP2015] 提高组 洛谷P2615 神奇的幻方
题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...
- 洛谷-神奇的幻方-NOIP2015提高组复赛
题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,--,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...
随机推荐
- Nested Classes
http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html package priceton; /* * Copyright (c) ...
- 【题解】[P4178 Tree]
[题解]P4178 Tree 一道点分治模板好题 不知道是不是我见到的题目太少了,为什么这种题目都是暴力开值域的桶QAQ?? 问点对,考虑点分治吧.直接用值域树状数组开下来,统计的时候直接往树状数组里 ...
- ThreadLocalMap里Entry声明为WeakReference
Java里,每个线程都有自己的ThreadLocalMap,里边存着自己私有的对象.Map的Entry里,key为ThreadLocal对象,value即为私有对象T.在spring MVC中,常用T ...
- mysql 查看或者修改数据库密码
首先启动命令行 1.在命令行运行:taskkill /f /im mysqld-nt.exe 下面的操作是操作mysql中bin目录下的一些程序,如果没有配置环境变量的话,需要切换到mysql的bin ...
- [2018-11-03]2018年10月28日宁波dotnet社区活动回顾及下次活动预告
离上次活动,有半年了,汗.之后尽量保证每月一次,以组织为主,多邀请嘉宾来分享. 本次活动不足之处 人手不足:由于活动组织事项受限于人手(目前就我一个,这次活动前后我又应邀给大红鹰学院应届生介绍dotn ...
- jQuery 的文档操作
在 js 中也有DOM操作,也可以进行 增删改查 ,但是通过 js 的DOM操作会发现,我的天哪,代码好多.但是 jQuery的文档操作就少了很多. js 中 DOM 的示例 : var box = ...
- nodejs中的子进程,深入解析child_process模块和cluster模块
Node.js的进程管理 node遵循的是单线程单进程的模式,node的单线程是指js的引擎只有一个实例,且在nodejs的主线程中执行,同时node以事件驱动的方式处理IO等异步操作.node的 ...
- html5/CSS3鼠标滑过图片特效插件
在线演示 本地下载
- ios审核过程十大常见被拒问题
欢迎加入ios马甲包经验交流群,群聊号码:744520623 2018年伊始,苹果并没有因为新年的气氛而对CP们“网开一面”.频繁锁榜.调整排名规则以及关键词覆盖算法……不断抛出的大动作,让CP们叫苦 ...
- IntelliJ IDEA 中详细图解记录如何连接MySQL数据库