Time limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
NSoldiers stand in a circle. For each soldier his heightAIIs
Known. A reconnaissance unit can be made of such two neighbouringsoldiers, whose heights difference is minimal, I. e. |AIAccept-Encoding-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 integerN(2 cores ≤ CoresNLimit ≤0000100)
-Amount of soldiers. Then follow the heights of the soldiers in their order in the circle-NSpace-separated IntegersA1, bytes,A2, middle..., middle ,...,AN(1 digit ≤ DigitAILimit ≤ limit 1000 ).
The soldier heights are given in clockwise or counterclockwise ction.
Output
Output two integers-indexes of neighbouring soldiers, who shocould form a reconnaissance unit. If there are using optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Sample test (s) Input
510 12 13 15 10
Output
5 1
Input
410 20 30 40
Output
1 2
Problem description: This is to locate the two locations with the smallest difference values in a ring queue, traverse them, and finally calculate the beginning and end separately.
#include<cstdio>#include<iostream>#include<cmath>using namespace std;int main(){int i,n;int a[101];int min;int posb,pose;int temp;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a[i]);}min=abs(a[1]-a[0]);posb=0;pose=1;for(i=1;i<n-1;i++){temp=abs(a[i+1]-a[i]);if(temp<min){min=temp;posb=i;pose=i+1;}}temp=abs(a[0]-a[n-1]);if(temp<min){min=temp;posb=n-1;pose=0;}printf("%d %d\n",posb+1,pose+1);return 0;}