本文主要是介绍CF #283 (Div. 2) A.(屏蔽数组元素),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:http://codeforces.com/contest/496/problem/A
解题思路:
n不是很大,所以暴力。每次屏蔽掉a[ i ]中的一个元素,注意头和尾不能屏蔽。屏蔽后当i == j 时做特殊处理,即cnt = a[ i+ 1 ] - a[ i - 1 ]。最后更新最小值即可。
完整代码:
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;
int a[1000001];
int main()
{#ifdef DoubleQfreopen("in.txt","r",stdin);#endifstd::ios::sync_with_stdio(false);std::cin.tie(0);int n;while(cin >> n){for(int i = 0 ; i < n ; i ++)cin >> a[i];int sum;int ans = INF;int cnt;for(int j = 1 ; j < n - 1 ; j ++){sum = -INF;cnt = 0;for(int i = 1 ; i < n ; i++){if(i == j){cnt = a[i + 1] - a[i - 1];i ++;}elsecnt = a[i] - a[i - 1];if(cnt > sum)sum = cnt;}if(sum < ans)ans = sum;}cout << ans << endl;}
}
这篇关于CF #283 (Div. 2) A.(屏蔽数组元素)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!