NOIP模拟赛1(one)
题目描述 Description###
很久以前,有一个序列,序列里填了一些非负整数。
\(zzq\) 每次可以选择序列的一个前缀,把这个前缀里的数都-1,如果这个前缀
中有 0 操作就无法进行。
\(zzq\) 想让序列中最大的数尽量小,请求出这个值。
输入描述 Input Description###
第一行一个整数 \(n\) ,表示序列的长度。
第二行 \(n\) 个整数,表示这个序列。
输出描述 Output Description###
经过若干次操作后序列中最大的数最小能是多少。
样例输入 Sample Input###
3
2 3 3
样例输出 Sample Output###
1
数据范围及提示 Data Size & Hint###
对于 20%的数据,\(n<=5\) ,\(0<=\) 序列中的每个数\(<=3\) 。
对于 50%的数据,\(n<=100\) 。
对于 100%的数据,\(1<=n<=100000\) ,\(0<=\) 序列中的每个数$<=10^8 $ 。
之前的一些废话###
题解###
二分答案,然后倒着找到第一个比当前二分值大的数,依次减,判断是否小于\(0\) 即可。
代码###
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
inline int read()
{
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
const int maxn=100010;
int n,A[maxn],L,R=100000000,ans=100000000;
bool judge(int index)
{
int pos=n;
while(pos>0 && A[pos]<=index)pos--;
if(pos==0){ans=min(ans,index);return 1;}
int MAX=0,tmp;
for(int i=pos;i>0;i--)
{
tmp=A[i]-index;
MAX=max(MAX,tmp);
if(A[i]-MAX<0)return 0;
}
ans=min(ans,index);
return 1;
}
int main()
{
n=read();
for(int i=1;i<=n;i++)A[i]=read();
while(R-L>1)
{
int mid=(L+R)>>1;
if(judge(mid))R=mid;
else L=mid;
}
judge(L);judge(R);
printf("%d\n",ans);
return 0;
}
总结###
听说有\(O(n)\) 做法。
NOIP模拟赛1(one)的更多相关文章
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)
A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...
随机推荐
- alipay sign error
阴影部分地址参数有问题: <PAY_COMPLETE_PAGE_URL><![CDATA[https://baoxian.itaiping.com/ae-console/remote ...
- 解决 eclipse出现 Address already in use: bind,以及tomcat端口占用
在项目开发中,有时候我们发现回报这个错:解决 eclipse出现 Address already in use: bind 产生的原因是端口占用,比如你的8080端口,已经有一个进程在访问使用,但是你 ...
- #undef常用法
Copy from C语言中#undef的语法是: #undef 标识符 用来将前面定义的宏标识符取消定义. 整理了如下几种常见用法,如果以后发现其他的再添加进来. 1.在一个程序块中用完宏定义后,为 ...
- servlet重点知识总结
Servlet Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层. ...
- BoW算法及DBoW2库简介(二)
一.BoW算法 用OpenCV实现了最简单的BoW算法进行了一次小规模的图像检索任务,使用UKbench数据库,算法原理和网上的描述差不多,使用K-means算法进行聚类,这里使用KDTree算法进行 ...
- perl: warning: Setting locale failed. 解决
perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAG ...
- Mac下vim安装taglist
1 安装taglist taglist 的安装非常简单.从vim官网的这个链接 http://www.vim.org/scripts/script.php?script_id=273,就可以下载到ta ...
- SAS与SATA的区别
SAS SATA的区别 协议方面 SAS(Serial Attached SCSI)即串行连接SCSI,SATA(Serial Advanced Technology Attachment)即串行高级 ...
- FastJson中的ObjectMapper对象的使用详解
写在前面:开发中经常用到json和对象的相互转换,下面将列出FastJson中ObjectMapper对象的API的使用 一.maven工程中pom导入<dependency> <g ...
- asp.net 关于gridview使用的一些小技巧
gridview中嵌套控件示例 —— 添加了一个linkbutton 前台: <asp:GridView ID="gv2" runat="server" ...