题目描述 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)的更多相关文章

  1. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  2. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  3. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  4. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

  5. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

  6. 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...

  7. 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...

  8. CH Round #58 - OrzCC杯noip模拟赛day2

    A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...

  9. CH Round #52 - Thinking Bear #1 (NOIP模拟赛)

    A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...

  10. CH Round #49 - Streaming #4 (NOIP模拟赛Day2)

    A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...

随机推荐

  1. 16.输入密码查看 flag

    直接进行burpsuite 的 intruder 爆破模块进行爆破, 得到密码为 13579. 输入进去得到flag

  2. HEC-ResSim原文档

              HEC-ResSim Reservoir System Simulation             User's Manual       Version 3.1 May 201 ...

  3. Educational Codeforces Round 37 (Rated for Div. 2) E. Connected Components? 图论

    E. Connected Components? You are given an undirected graph consisting of n vertices and edges. Inste ...

  4. Python程序中的进程操作-进程池(multiprocess.Pool)

    目录 一.进程池 二.概念介绍--multiprocess.Pool 三.参数用法 四.主要方法 五.其他方法(了解) 六.代码实例--multiprocess.Pool 6.1 同步 6.2 异步 ...

  5. 栈与后缀表达式C实现

    #include<stdio.h> #include<stdlib.h> typedef char datatype; typedef struct stack { int t ...

  6. 浏览器记住密码的自动填充Input问题完美解决方案

    1.input 前from和input占位隐藏 <form style="width:0;height:0;display:none;"> <input type ...

  7. java高并发系列 - 第10天:线程安全和synchronized关键字

    这是并发系列第10篇文章. 什么是线程安全? 当多个线程去访问同一个类(对象或方法)的时候,该类都能表现出正常的行为(与自己预想的结果一致),那我们就可以所这个类是线程安全的. 看一段代码: pack ...

  8. python 对Unicode解码

    打印: print('我喜欢你'.encode('unicode_escape')) 得到Unicode编码: b'\\u6211\\u559c\\u6b22\\u4f60 将上面的编码赋值给str后 ...

  9. 总结了Python中的22个基本语法

    "人生苦短,我用Python".Python编程语言是最容易学习.并且功能强大的语言.只需会微信聊天.懂一点英文单词即可学会Python编程语言.但是很多人声称自己精通Python ...

  10. Java 小游戏 - 井字棋 v1.0 (初步完成) (2018.4.16更新)

      井字棋游戏初步完成 实现功能:输入位置数据->打印棋盘->判断是否胜利->继续游戏/退出游戏 缺点:没有清屏函数   判断胜利方法太过无脑    package MYGAME; ...