A - Reconnaissance 2 士兵 立正啦…

Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d& %I64u

[Submit [GoBack  [Status]

Description

n soldiers standin a circle. For each soldier hisheight ai is known. Areconnaissance unit can be made of suchtwo 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 anypair 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 intheir order in the circle — n space-separatedintegersa1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heightsare given in clockwise or counterclockwise direction.

Output

Output two integers — indexes of neighbouring soldiers,who should form a reconnaissance unit. If there are many optimumsolutions, output any of them. Remember, that the soldiers stand ina circle.

Sample Input

Input
5

10 12 13 15 10

Output
5 1

Input
4

10 20 30 40

Output
1 2


[Submit [GoBack  [Status]

题目要求:求站成一圈的士兵相邻身高差最小的两士兵的编号(有多对的话取找到的第一队)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
        int n,a[1000],i,j,min;
        while(scanf("%d",&n)!=EOF)
        {
                min=10001;
                  cin>>a[1];
                for(i=2;i<=n;i++)
                {
                        cin>>a[i];
                      if(abs(a[i]-a[i-1])<min)
                          {   min=abs(a[i]-a[i-1]);
                           j=i;
                          }
                }
       if(abs(a[n]-a[1])<min)
                   cout<<n<<" 1"<<endl;
           else
                   cout<<j-1<<" "<<j<<endl;
           }
        return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值