首页 > 其他分享 >CodeForces 34A Reconnaissance 2

CodeForces 34A Reconnaissance 2

时间:2023-04-20 21:38:40浏览次数:67  
标签:cha 34A int CodeForces ii jj Input Reconnaissance include


 Reconnaissance 2


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


Submit  Status  Practice  CodeForces 34A


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|



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



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;
}

标签:cha,34A,int,CodeForces,ii,jj,Input,Reconnaissance,include
From: https://blog.51cto.com/u_14834528/6210671

相关文章

  • codeforces round The Monster and the Squirrel 529B (数学规律)
    TheMonsterandtheSquirrelTimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionArithemonsteralwayswakesupveryearlywiththefirstrayofthesunandthefirstthingshedoesisfeedinghersqu......
  • Codeforces Round 850 (Div. 2, based on VK Cup 2022 - Final Round) E. Monsters (h
    传送门详细题解传送门  抄的ygg代码,向在这里说一下刚开始没看懂的部分。  求答案的时候是把所有的当前为止的所有数值加起来减去一个从1开始并且公差为1的等差数列的前size项和。其中size是当前最多能用到哪个位置,满足前size项能构成1,2,3,....,sz这样的形式。  假设我们......
  • CodeForces - 610B Vika and Squares (模拟)
    CodeForces-610BVikaandSquaresTimeLimit: 2000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionVikahas n jarswithpaintsofdistinctcolors.Allthejarsarenumberedfrom 1 to n andthe......
  • CodeForces - 659C Tanya and Toys (map&模拟)
    CodeForces-659CTanyaandToysTimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionInBerlandrecentlyanewcollectionoftoyswentonsale.Thiscollectionconsistsof 109 typesof......
  • CodeForces - 367B Sereja ans Anagrams (map)
    CodeForces-367BSerejaansAnagramsTimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionSerejahastwosequences a and b andnumber p.Sequence a consistsof n integers a1, a......
  • CodeForces - 368C Sereja and Algorithm (找规律&模拟)
    CodeForces-368CSerejaandAlgorithmTimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionSerejalovesallsortsofalgorithms.Hehasrecentlycomeupwithanewalgorithm,whichreceiv......
  • CodeForces - 616E Sum of Remainders (数论)大数取余求和 好题
    CodeForces-616ESumofRemaindersTimeLimit: 2000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionCalculatethevalueofthesum: nmod1 + nmod2 + nmod3 +...+ nmodm.Astheresultcanbeve......
  • Educational Codeforces Round 113 (Rated for Div. 2)
    题目链接B核心思路这个题目我觉得很好。首先分析下吧,如果有人需要执行操作二那么我们肯定就是给他们都打上平局是最优的。那么如果有人需要执行操作一呢,那么我们就可以把这些需要执行操作1的都搞一起。然后是他们成一个环。这样肯定就保证了每个人都会赢上一次。C核心思路......
  • Codeforces Round 866 (Div. 2)
    A.Yura'sNewName一个简单的dp,状态是\(f[i][0/1]\)表示前\(i\)位变成合法的且最后一位是^或_的最小代价。如果是_只能从^转移过来,如果是^则都可以转移过来#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ strings; cin>>s; intn=s.size(); if(n=......
  • Codeforces Dp
    ZeroRemainderSum  采用辅助数组$ndp[m+1][\frac{m}{2}][k]$来求出每一行中在当前第$i$列,取了$j$个物品,总和模$k$的余数是$t$的最大和是多少。用$dp[n+1][k]$来转移每一行的状态。#include<bits/stdc++.h>usingnamespacestd;const......