题目链接:http://codeforces.com/contest/34/problem/A
n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — nspace-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction.
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
5 10 12 13 15 10
5 1
4 10 20 30 40
1 2
题目大意:n个士兵围成一个圆,找出相邻的两个士兵使得价值差最小
题目思路:暴力就行
代码:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define FOU(i,x,y) for(int i=x;i<=y;i++)
#define FOD(i,x,y) for(int i=x;i>=y;i--)
#define MEM(a,val) memset(a,val,sizeof(a))
#define PI acos(-1.0)
const double EXP = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll MINF = 0x3f3f3f3f3f3f3f3f;
const double DINF = 0xffffffffffff;
const int mod = 1e9+7;
const int N = 1e6+5;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
std::ios::sync_with_stdio(false);
int n;
int a[105];
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
int minn=INF;
int loc;
for(int i=1;i<n;i++)
{
if(abs(a[i]-a[i+1])<minn)
{
minn=abs(a[i]-a[i+1]);
loc=i;
}
}
if(abs(a[n]-a[1])<minn)
{
cout<<n<<" 1"<<endl;
}
else
cout<<loc<<" "<<loc+1<<endl;
return 0;
}