2016noip exercises 3. Random

#include <cstdio> // 2016noip exercises, 3, randomized (not open o2 optimization, over five points, optimized open o2, over nine points)
#include <iostream>
#include <cmath>
#include <algorithm>
a using STD namespace;
int A [1000005];
int n-, S, T, ANS;

inline int read () {// read optimization, into a string of numbers, uniform reading;
 char C;
 int X;
 the while (C = getchar (), C < '0' || C> '. 9') ;
 X = C-'0 ';
 the while (C = getchar (),' 0 '<&& C = C <='. 9 ')
  X = X + C * 10-'0';
 return X;
}

main int ()
{
 The freopen ( "random.in", "R & lt", stdin);
 The freopen ( "random.out", "W", stdout);
 n-= Read ();
 for (int I =. 1; I < = n-; I ++)
 A [I] = Read ();
 ANS = 1000005;
 for (int I =. 1; I <= n-; I ++)
 {
  int MAXN = 1000005;
  for (int J = I +. 1; J <= n-; J ++)
  {
   S = ABS (A [I] -a [J]); // number of two-phase absolute value
   IF (MAXN> S)
   {
    MAXN = S;
    T = (I-J +. 1); // interval length
    iF (t <S) ANS = min (ANS, MAXN);
    the else {
     ANS = min (ANS, t);
     BREAK; // i and j since moving away, thus increasing t, when t great value, not updating the minimum
             // exit the loop j;
    }
   }
  }  
 }
 printf ( "% d ", years);
}

 

Published 20 original articles · won praise 1 · views 6337

Guess you like

Origin blog.csdn.net/yichengchangan/article/details/54896907