CodeForces 34A Reconnaissance 2

该问题描述了一个士兵圈中寻找身高差最小相邻士兵的任务。输入包含士兵人数及身高,输出是符合条件的士兵索引对。若有多组解,任选一组输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 Reconnaissance 2
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 Input

Input
5
10 12 13 15 10
Output
5 1
Input
4
10 20 30 40
Output
1 2
 
    
 
    
 
    
 
    
       大体题意:n个人围成一个圈,下面分别是n个人的身高,求这个圈里面的相邻的两个人身高差最小的编号是那两个?其中编号按输入数据的顺序排列,第一个是1,最后一个是n


AC代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int a[2101];
        int ii,jj;
        int cha;
        int min = 100000;
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
            if(i!=1)
            {
                cha = fabs(a[i] - a[i-1]);
                if(min > cha)
                {
                    min  = cha;
                    ii = i-1;
                    jj = i;
                }
            }

        }
        cha = fabs(a[1] - a[n]);
        if(min > cha)
        {
            min  = cha;
            ii = n;
            jj = 1;
        }
        printf("%d %d\n",ii,jj);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

叶孤心丶

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

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

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

打赏作者

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

抵扣说明:

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

余额充值