【Educational Codeforces Round 35 A】 Nearest Minimums

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

找出最小的数字的位置。
最近的肯定是相邻的某对。

【代码】

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5;

int n;
int a[N+10],mi;

int main(){
    #ifdef LOCAL_DEFINE
        freopen("rush_in.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    for (int i = 1;i <= n;i++) cin >> a[i];
    mi = a[1];
    for (int i = 2;i <= n;i++) mi = min(mi,a[i]);
    int ans = -1,pre=-1;
    for (int i = 1;i <= n;i++){
        if (a[i]==mi){
            if (pre==-1){
                pre = i;
            }else{
                if (ans==-1){
                    ans = i-pre;

                }else{
                    ans = min(ans,i-pre);
                }
                pre = i;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

原文地址:https://www.cnblogs.com/AWCXV/p/8143099.html

时间: 2024-07-30 20:15:42

【Educational Codeforces Round 35 A】 Nearest Minimums的相关文章

【Educational Codeforces Round 35 D】Inversion Counting

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 排列中交换任意两个数字. 排列的逆序对个数的奇偶性会发生变化. 翻转这个过程其实就是len/2对数字发生交换. 交换了偶数次的话,不变,否则奇偶性发生改变. 先暴力求出一开始的逆序对个数就好 [代码] #include <bits/stdc++.h> using namespace std; const int N = 1500; int n,a[N+10],cnt,now,m; void out(int x){ if (x=

【Educational Codeforces Round 35 C】Two Cakes

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 直觉题. 感觉情况会很少. 毕竟间隔太大了.中间肯定有一些数字达不到. 有1肯定可以 2 2 x肯定可以 3 3 3也可以 2 4 4也可以. 就这样 [代码] #include <bits/stdc++.h> using namespace std; vector <int> v; int main(){ #ifdef LOCAL_DEFINE freopen("rush_in.txt", &

【Educational Codeforces Round 36 A】 Garden

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举用哪一个桶就好 [代码] #include <bits/stdc++.h> using namespace std; int n,k,x; int main(){ #ifdef LOCAL_DEFINE freopen("rush_in.txt", "r", stdin); #endif ios::sync_with_stdio(0),cin.tie(0); cin >>

【Educational Codeforces Round 37 C】 Swap Adjacent Elements

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然l..r这一段连续的1可以把l..r+1变成有序的. 那么就把所有的连续1段变成有序的就好. 看看最后是不是升序即可. [代码] #include <bits/stdc++.h> using namespace std; const int N = 2e5; int n,a[N+10],b[N+10]; char s[N+10]; int main(){ #ifdef LOCAL_DEFINE freopen("

【Educational Codeforces Round 37 E】Connected Components?

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] bfs. 用一个链表来记录哪些点已经确定在某一个联通快里了. 一开始每个点都能用. 然后从第一个点开始进行bfs. 然后对于它的所有连接着的点(输入的图的补图 看看它是不是之前进行过bfs,如果是的话.就跳过.(可以用链表直接跳过.即沿着链表枚举它的出度. 否则.把这个点从链表中删掉.然后把这个点加入队列.继续bfs即可. 这样已经确定联通了的点之间不会再访问. 链表加速了寻找某个点的出度的过程. 且由于当n很大的时候.m只有2

【Educational Codeforces Round 37 A】 Water The Garden

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 记录下水龙头在哪些位置. 然后每秒钟把index-i和index+i改变状态一下就好(置1 [代码] #include <bits/stdc++.h> using namespace std; const int N = 200; int n,k; int a[N+10],x[N+10]; int ok(){ for (int i = 1;i <= n;i++) if (a[i]==0) return 0; return

Educational Codeforces Round 35 E. Stack Sorting 模拟

Educational Codeforces Round 35 E. Stack Sorting 题意:长度为 n 的序列 a[] ,a[] 里的数是 1~n,一个空栈 s,一个空序列 b[].两个操作:把 a[] 的第一个数放到 s 里: 或者把 s 的栈顶元素加到 b[] 的末尾. 如果你能通过这两个操作把 a[] 的数最后都放入 b[] 中,且 b[] 是升序的,那就可说 a[] 是 stack-sortable . 现在给出 a[] 的前 k 个数,要你确定是否有满足 stack-sor

Educational Codeforces Round 35 (Rated for Div. 2)

A. Nearest Minimums 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

【Educational Codeforces Round 81 (Rated for Div. 2) A】Display The Number

题目链接 [题解] 优先用2个棒子来凑1. 如果为奇数的话,多出来一根用3根来凑个7放在开头 [代码] #include <bits/stdc++.h> using namespace std; int main(){ #ifdef LOCAL_DEFINE freopen("E:\\rush.txt","r",stdin); #endif // LOCAL_DEFINE ios::sync_with_stdio(0),cin.tie(0); int T