A. Reconnaissance 2

来源:互联网 发布:mac 梦幻西游手游网页 编辑:程序博客网 时间:2024/05/29 01:51
A. Reconnaissance 2
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouringsoldiers, 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.

Input

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 —n space-separated integers a1,?a2,?...,?an (1?≤?ai?≤?1000). The soldier heights are given in clockwise or counterclockwise direction.

Output

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.

Sample test(s)
input
5
10 12 13 15 10
output
5 1
input
4
10 20 30 40
output
1 2


/* ***********************************************
Author :
Created Time :2015/6/14 12:18:25
File Name :7.cpp
************************************************ */

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;

bool cmp(int a,int b){
return a>b;
}
int a[maxn];
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
int n;
int x,y;
while(cin>>n){
for(int i=1;i<=n;i++)
cin
>>a[i];
a
[n+1]=a[1];
int Min=INF;
for(int i=2;i<=n+1;i++){
if(abs(a[i]-a[i-1])<Min){
Min=abs(a[i]-a[i-1]);
x
=i;y=i-1;
if(x>n)x=1;

}
}
cout
<<y<<" "<<x<<endl;
}
return 0;
}

0 0
原创粉丝点击