Educational Codeforces Round 35 A. Nearest Minimums【预处理】
【题目链接】:
Educational Codeforces Round 35 (Rated for Div. 2)
2 seconds
256 megabytes
standard input
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.
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.
Print the only number — distance between two nearest minimums in the array.
2
3 3
1
3
5 6 5
2
9
2 1 3 5 4 1 2 3 1
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【预处理】的更多相关文章
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- 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 ...
- Educational Codeforces Round 35
Nearest Minimums 相同的数里最小的数里的最小距离 Solution Two Cakes Solution Three Garlands 瞎比试 Solution Inversion C ...
- 【Educational Codeforces Round 35 A】 Nearest Minimums
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找出最小的数字的位置. 最近的肯定是相邻的某对. [代码] #include <bits/stdc++.h> using ...
- Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化
链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...
- Educational Codeforces Round 1(C. Nearest vectors)
题目链接:http://codeforces.com/problemset/problem/598/C 题意是给你一个数n,下面n行,每行给你横坐标x和纵坐标y(x != 0 && y ...
- Educational Codeforces Round 1 C. Nearest vectors 极角排序
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/ ...
- Educational Codeforces Round 35 B/C/D
B. Two Cakes 传送门:http://codeforces.com/contest/911/problem/B 本题是一个数学问题. 有a个Ⅰ类球,b个Ⅱ类球:有n个盒子.将球放入盒子中,要 ...
- Three Garlands~Educational Codeforces Round 35
C. Three Garlands time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
随机推荐
- Kubespray部署Kubernetes 1.13.0(使用本地镜像仓库)
1. 下载kubespray # git clone https://github.com/kubernetes-sigs/kubespray.git # cd kubespray # pip ins ...
- IOS开发---菜鸟学习之路--(十三)-利用MBProgressHUD进行异步获取数据
本章将介绍如何利用MBProgressHUD实现异步处理数据. 其实我本来只是像实现一个加载数据时提示框的效果,然后问了学长知道了这个类,然后就使用了 接着就发现了一个“BUG” 再然后就发现原来MB ...
- Python+Selenium基础篇之2-打开和关闭火狐浏览器
本节介绍如何初始化一个webdriver实例对象driver,然后打开和关闭firefox浏览器.要用selenium打开fiefox浏览器.首先需要去下载一个driver插件geckodriver. ...
- Docker Hadoop LAMP安装配置教程
以下教程来自九章算法. 1.How to install Dockerhttps://bupt.quip.com/YehSAR4qnGqB 2.How to set up hadoop environ ...
- shell之常用命令
一些技巧 ctrl+alt+f1切换至命令行模式 ctrl+alt+f7切换至图形界面 命令行编辑: 光标跳转 ctrl+a 行首 ctrl+e 行尾 ctrl+d 删除 ctrl+u 删除光标至行首 ...
- java面试需要准备什么呢?c++可以看看
作者:Mingche Su链接:https://zhuanlan.zhihu.com/p/20545626来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 语言知识点:以 ...
- astyle使用基础教程
astyle使用基础教程 转自: http://babybandf.blog.163.com/blog/static/61993532010112205811797/ astyle是一个我自己常用的开 ...
- POJ 3494 Largest Submatrix of All 1’s 单调队列||单调栈
POJ 3494 Largest Submatrix of All 1’s Description Given a m-by-n (0,1)-matrix, of all its submatrice ...
- WINDOWS开发PHP7扩展
最近在做个项目,需要用到唯一ID的生成,原本在Java和Delphi中,做了一个生成20位字符串(160bit)形式的唯一ID的算法,但是对比GUID(128bit),除了看起来比他短之外,其他并无优 ...
- springboot的api测试