HZAU 1006 The Nearest Same Chocolate

原题
签到题
和2015年上海区域赛一题貌似一样的 有空找来看看

#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAX_N = 100 + 9;
void solve()
{
  int a[MAX_N];
  memset(a, 0, sizeof(a));
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[j] == a[i] && j - i < ans) ans = j - i;
    }
  }
  printf("%d\n", ans);
}
int main()
{
// freopen("input.txt", "r", stdin);
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    solve();
  }
}

你可能感兴趣的:(HZAU 1006 The Nearest Same Chocolate)