Codeforces Round #283 (Div. 2) A. Minimum Difficulty 暴力水题
2 seconds
256 megabytes
standard input
standard output
Mike is trying rock climbing but he is awful at it.
There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, ai < ai + 1 for all i from 1 to n - 1; we will call such sequence a track. Mike thinks that the track a1, ..., an has difficulty  . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
. In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights a1, ..., an. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1, 2, 3, 4, 5) and remove the third element from it, we obtain the sequence (1, 2, 4, 5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold.
The first line contains a single integer n (3 ≤ n ≤ 100) — the number of holds.
The next line contains n space-separated integers ai (1 ≤ ai ≤ 1000), where ai is the height where the hold number i hangs. The sequence ai is increasing (i.e. each element except for the first one is strictly larger than the previous one).
Print a single number — the minimum difficulty of the track after removing a single hold.
3
1 4 6
5
5
1 2 3 4 5
2
5
1 2 3 7 8
4
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4.
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1001
const int inf=0x7fffffff; //无限大
int h[maxn];
int main()
{
int n;
cin>>n;
cin>>h[];
int minn=;
for(int i=;i<n-;i++)
{
cin>>h[i];
minn=max(h[i]-h[i-],minn);
}
cin>>h[n-];
minn=max(h[n-]-h[n-],minn);
//cout<<minn<<endl;
int kiss=;
for(int i=;i<n;i++)
{
kiss=min(h[i]-h[i-],kiss);
}
//cout<<kiss<<endl;
cout<<max(kiss,minn)<<endl;
return ;
}
Codeforces Round #283 (Div. 2) A. Minimum Difficulty 暴力水题的更多相关文章
- Codeforces Round #283 (Div. 2) B. Secret Combination 暴力水题
		B. Secret Combination time limit per test 2 seconds memory limit per test 256 megabytes input standa ... 
- Codeforces Round #283 (Div. 2) A. Minimum Difficulty【一个数组定义困难值是两个相邻元素之间差的最大值。 给一个数组,可以去掉任意一个元素,问剩余数列的困难值的最小值是多少】
		A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ... 
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
		题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ... 
- 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination
		题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ... 
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
		Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ... 
- Codeforces Round #298 (Div. 2) A、B、C题
		题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ... 
- Codeforces Round #283 (Div. 2) A ,B ,C 暴力,暴力,暴力
		A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ... 
- Codeforces Round #283 (Div. 2)  A
		解题思路:给出一个递增数列,a1,a2,a3,-----,an.问任意去掉a2到a3之间任意一个数之后, 因为注意到该数列是单调递增的,所以可以先求出原数列相邻两项的差值的最大值max, 得到新的一个 ... 
- Codeforces Round #283 (Div. 2) C. Removing Columns 暴力
		C. Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard ... 
随机推荐
- ASP.NET MVC5 支持PUT 和DELETE
			Web.config <configuration> <system.webServer> <handlers> <remove name="Ext ... 
- FM的推导原理--推荐系统
			FM:解决稀疏数据下的特征组合问题 Factorization Machine(因子分解机) 美团技术团队的文章,觉得写得很好啊:https://tech.meituan.com/deep-unde ... 
- windows系统 安装MongoDB
			1.下载 官网下载地址:https://www.mongodb.com/download-center#community 2.配置MongoDB a.在e:\MongoDB(可随意起)下面建一个da ... 
- iframe框架加载完成后执行函数
			var iframe = document.createElement("iframe"); iframe.src = "http://www.baidu.com/&qu ... 
- AdvStringGrid 列宽度、列移动、行高度、自动调节
			那么有没有办法,让客户自己去调整列的宽度呢? 那么有没有办法 让列宽度.行高度 随着内容而自动变换呢: unit Unit5; interface uses Winapi.Windows, Winap ... 
- 修饰符(动态String数组篇)--- 常用 解除疑问。
			1.无修饰符----是直接传基本类型的地址过来,并没有把基本类型的指针复制一份入栈,所以一旦修改就是修改原来的值. 2.const 修饰符 与 无修饰符一致. 3.var修饰符 与 上一致. 4.ou ... 
- SQLServer系统变量使用
			1.@@IDENTITY返回最后插入的标识值.这个变量很有用,当你插入一行数据时,想同时获得该行的的ID(标示列),就可以用@@IDENTITY示例:下面的示例向带有标识列的表中插入一行,并用 @@I ... 
- C#实现盛大盛付通充值卡状态查询
			今天有这样一需求,要求能够查询盛付通卡的状态,官网如下 http://www.801335.com/status/index.htm 刚一打开网址,发现两个输入框加一个验证码,心中一喜不是小 cas ... 
- python和redis简单交互
			python和redis简单交互 1.安装redis模块 pip3 install redis 2.redis模块简单使用: # /usr/bin/env python3 import redis c ... 
- tp5总结(四)
			数据库 1.数据库配置 1-1.配置文件配置[http://ww:7070/tp5-3/public/] 1-2.Db::connect配置[数组和字符串方式][http://ww:7070/tp5- ... 
