Educational Codeforces Round 35 Div.2 A. Nearest Minimums

Problem

http://codeforces.com/contest/911/problem/A

C++ Code

#include 
#include 
using namespace std;

int main()
{
    int m = 1000000000;
    int a;
    vector  vec;
    int n;
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++) 
    {
        scanf("%d", &a);
        if (a < m) 
        { 
            m = a; 
            vec.clear(); 
        }
        if (a == m) 
        {
            vec.push_back(i);           
        }
    }
    
    int distance  = 100000;
    for (int i = 0; i + 1 < vec.size(); i++)
    {
        distance = min(distance, vec[i + 1] - vec[i]);
    }
        
    printf("%d\n", distance);
    
    return 0;
}




更多内容请关注微信公众号


wechat.jpg

你可能感兴趣的:(Educational Codeforces Round 35 Div.2 A. Nearest Minimums)