【水数组】#34 A. Reconnaissance 2

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


一个循环数组找相邻最小值

#include <cmath>   
#include <cstdio>  
#include <string>  
#include <cstring>  
#include <iostream>  
#include <algorithm>
using namespace std;

int main()
{
	int n,a0,alast,anow;
	int index,minimal=9999;
	cin>>n;
	cin>>a0;
	alast=a0;
	for(int i=1;i<n;i++)
	{
		cin>>anow;
		if(abs(anow-alast)<minimal)
		{
			minimal=abs(anow-alast);
			index=i+1;
		}
		alast=anow;
	}
	if(abs(a0-anow)<minimal)	cout<<n<<" 1";
	else cout<<index-1<<" "<<index;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值