【题目链接】:

Educational Codeforces Round 35 (Rated for Div. 2)

A. Nearest Minimums
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array of n integer numbers a0, a1, ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.

Input

The first line contains positive integer n (2 ≤ n ≤ 105) — size of the given array. The second line contains n integers a0, a1, ..., an - 1(1 ≤ ai ≤ 109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.

Output

Print the only number — distance between two nearest minimums in the array.

Examples
input
2
3 3
output
1
input
3
5 6 5
output
2
input
9
2 1 3 5 4 1 2 3 1
output
3

【题意】:给出一个n个整数的数组。找出两个最小值之间的最接近的(最近的)距离。

【时间复杂度&&优化】:O(1e5)

【分析】:先在读入时预处理找到最小值。再开一个On循环,当某个数初次等于最小值时记录一下他的下标赋给last,非初次出现的等于最小值的直接寻找最近距离。

【代码】:

#include <bits/stdc++.h>

using namespace std;

int n;
int a[];
int main(){
scanf("%d",&n);
int mi=1e9+;
for(int i=;i<n;i++){
scanf("%d",&a[i]);
mi=min(mi,a[i]);
}
int ans=1e9;
for(int la=-,i=;i<n;i++){
if(a[i]==mi){
if(la!=-){
ans=min(ans,i-la);
}
la=i;
}
}
printf("%d\n",ans);
return ;
}

预处理

Educational Codeforces Round 35 A. Nearest Minimums【预处理】的更多相关文章

  1. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  2. Educational Codeforces Round 35 (Rated for Div. 2)A,B,C,D

    A. Nearest Minimums time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Educational Codeforces Round 35

    Nearest Minimums 相同的数里最小的数里的最小距离 Solution Two Cakes Solution Three Garlands 瞎比试 Solution Inversion C ...

  4. 【Educational Codeforces Round 35 A】 Nearest Minimums

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找出最小的数字的位置. 最近的肯定是相邻的某对. [代码] #include <bits/stdc++.h> using ...

  5. Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化

    链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...

  6. Educational Codeforces Round 1(C. Nearest vectors)

    题目链接:http://codeforces.com/problemset/problem/598/C 题意是给你一个数n,下面n行,每行给你横坐标x和纵坐标y(x != 0 && y ...

  7. Educational Codeforces Round 1 C. Nearest vectors 极角排序

    Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/ ...

  8. Educational Codeforces Round 35 B/C/D

    B. Two Cakes 传送门:http://codeforces.com/contest/911/problem/B 本题是一个数学问题. 有a个Ⅰ类球,b个Ⅱ类球:有n个盒子.将球放入盒子中,要 ...

  9. Three Garlands~Educational Codeforces Round 35

    C. Three Garlands time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. Python中bisect的使用方法

    Python中列表(list)的实现其实是一个数组,当要查找某一个元素的时候时间复杂度是O(n),使用list.index()方法,但是随着数据量的上升,list.index()的性能也逐步下降,所以 ...

  2. Hive将SQL转化为MapReduce的过程

    Hive将SQL转化为MapReduce的过程: Antlr定义SQL的语法规则,完成SQL词法,语法解析,将SQL转化为抽象语法树AST Tree 遍历AST Tree,抽象出查询的基本组成单元Qu ...

  3. 数据预处理之独热编码(One-Hot Encoding)

    问题的由来 在很多机器学习任务中,特征并不总是连续值,而有可能是分类值. 例如,考虑以下三个特征: ["male","female"] ["from ...

  4. loj6387 「THUPC2018」绿绿与串串 / String

    还是很好做的,大致就是manacher,每个位置为中心的最长回文串要是能抵到最右边就合法,要是能抵到最左边,那这个点的是否合法取决于以这个点为中心的最长回文串的右端点是否合法. #include &l ...

  5. msconfig.exe

    msconfig.exe 编辑 本词条缺少概述.名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧!   中文名 微软系统配置实用程序 外文名 msconfig.exe 出品者 Micros ...

  6. 2018安恒杯11月月赛 MISC

    题目放评论了 Numeric password 这次隐写没有按照套路出牌,很强. 记录一下 看来自主学习的能力很有待提高. 打开Numeric password.txt 中华文化博大精深,近日在教小外 ...

  7. BugKu-图穷匕见

    拿到图片后,先放到winhex,看看文件头是不是和jpg匹配,看看文件尾,不是FFD9 ,说明后边肯定是藏了什么东西. 顺便找一下文件尾有没有flag(估计是签到题目才会这样吧). binwalk跑一 ...

  8. 用户注册,登录API 接口

    Controer: <?php /** * @name UserController * @author pangee * @desc 用户控制器 */ class UserController ...

  9. [oldboy-django][2深入python] orm中auto_now =True, antu_now_add=True的应用

    DateTimeField.auto_now 这个参数的默认值为false,设置为true时,能够在保存该字段时,将其值设置为当前时间,并且每次修改model,都会自动更新.因此这个参数在需要存储“最 ...

  10. android AsyncTask使用限制

    由于AsyncTask内部是使用线程池(ThreadPoolExecutor)来管理要处理的任务的,所以AsyncTask的弊端就非常明确了:要extcute的任务数量超过线程池最大容量时,必然会报错 ...