A. Reconnaissance 2

Source: Internet
Author: User
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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.