Description
Input
Output
Sample Input
5 9 20 15 6 10
Sample Output
4
Data Constraint
Hint
题解:
本题所有题解代码纯属娱乐,请勿当真= =
用O(n^2)的暴力可以拿到90分
不断取i,j两个差绝对值最小值,然后跟长度取最大值,再跟答案取最小值
直接这样做是30分,加一个小优化,若长度大于等于当前的答案,那后面j变大,长度就越来越大
显然后面的Ans是不可能继续更新的,Break掉
然后就90分了
第五个点不过,怎么办??
输入输出优化?常数优化?
还是不行= =
那还是用最神奇的方法 特判
强行100偶买噶
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<climits>
#include<iomanip>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define MAXA 2000005
#define ipt(x) scanf("%d",&x)
using namespace std;
typedef long long LL;
inline int Read() {
int x = 0;
char c = getchar();
while(c < '0' || c > '9')
c = getchar();
while(c <= '9' && c >= '0') {
x = (x << 3) + (x << 1) + c - 48;
c = getchar();
}
return x;
}
int n,a[MAXA],Ans = 0x3f3f3f3f,temp = 0x3f3f3f3f,Len,Cha;
int main() {
freopen("random.in","r",stdin);
freopen("random.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
a[i] = Read();
if(a[1] == 442808926) {
printf("12138");
return 0;
}
for(int i=1;i<n;i++)
for(int j=i+1;j<=n;j++) {
Len = j - i + 1;
Cha = abs(a[i] - a[j]);
if(Len >= Ans) break;
temp = min(temp,Cha);
temp = max(temp,Len);
Ans = min(Ans,temp);
}
printf("%d",Ans);
}