博客
关于我
P3853 [TJOI2007]路标设置
阅读量:252 次
发布时间:2019-03-01

本文共 1510 字,大约阅读时间需要 5 分钟。

 

题目背景

B市和T市之间有一条长长的高速公路,这条公路的某些地方设有路标,但是大家都感觉路标设得太少了,相邻两个路标之间往往隔着相当长的一段距离。为了便于研究这个问题,我们把公路上相邻路标的最大距离定义为该公路的“空旷指数”。

题目描述

现在政府决定在公路上增设一些路标,使得公路的“空旷指数”最小。他们请求你设计一个程序计算能达到的最小值是多少。请注意,公路的起点和终点保证已设有路标,公路的长度为整数,并且原有路标和新设路标都必须距起点整数个单位距离。

输入格式

第1行包括三个数L、N、K,分别表示公路的长度,原有路标的数量,以及最多可增设的路标数量。

第2行包括递增排列的N个整数,分别表示原有的N个路标的位置。路标的位置用距起点的距离表示,且一定位于区间[0,L]内。

输出格式

输出1行,包含一个整数,表示增设路标后能达到的最小“空旷指数”值。

输入输出样例

输入 #1复制

101 2 10 101

输出 #1复制

51

说明/提示

公路原来只在起点和终点处有两个路标,现在允许新增一个路标,应该把新路标设在距起点50或51个单位距离处,这样能达到最小的空旷指数51。

50%的数据中,2 ≤ N ≤100,0 ≤K ≤100

100%的数据中,2 ≤N ≤100000, 0 ≤K ≤100000

100%的数据中,0 < L ≤10000000

发现自己越来越迷糊啥时候用第一个板子啥时候第二个板子了..纯属交一遍不行再改一遍。这道题自己当时的模拟有点小思路错误。

#include<iostream>#include<vector>#include<queue>#include<cstring>#include<cmath>#include<cstdio>#include<algorithm>using namespace std;const int maxn=1e5+10;typedef long long LL;LL a[maxn];LL L,N,K;LL check(LL mid){	LL cnt=0;LL start=0;	for(LL i=1;i<=N+1;i++) // 起点(0)  3   4 5 6 	{				if(a[i]-start>mid)		{			cnt+=(a[i]-start)/mid;			if ( (a[i]-start)%mid==0) cnt--;//可以是两倍三倍的大 		} 		start=a[i];///起点是一直变的,所以模拟要清楚,还不如a[i+1]-a[i] 	}			if(cnt>K) return 0;//看实际意义的check和二分后面的,决定是该提还是降 	else return 1; }LL bsearch(LL l,LL r){	while(l<r)	{		LL mid=(l+r)>>1;		if(check(mid)) r=mid;		else l=mid+1;	}	return l;}int main(void){  cin.tie(0);std::ios::sync_with_stdio(false);  cin>>L>>N>>K;  for(LL i=1;i<=N;i++) cin>>a[i];  sort(a+1,a+1+N);  a[N+1]=L;  //枚举相邻路标的最大距离  LL t=bsearch(1,L+1);  //只有起点和终点,没有其他路标时   if(t==L+1)  {   cout<<L<<endl;	  }   else cout<<t<<endl;return 0;}

转载地址:http://qtdt.baihongyu.com/

你可能感兴趣的文章
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No static resource favicon.ico.
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>