解题思路:给出一个递增数列,a1,a2,a3,-----,an.问任意去掉a2到a3之间任意一个数之后,

因为注意到该数列是单调递增的,所以可以先求出原数列相邻两项的差值的最大值max,

得到新的一个数列(比如先去掉a2),该数列相邻两项的差值的最大值为Max1=findmax(max,a3-a1)

再去掉 a3,得到该数列相邻两项的差值的最大值Max2=findmax(max,a4-a2)

------

再去掉 an-1,得到该数列相邻两项的差值的最大值Maxn-2=findmax(max,an-an-2)

题目要求的即为 max1,max2,max3,-----,maxn-2的最小值

A.

Minimum Difficulty

time limit per test2 seconds

memory limit per test256

megabytes inputstandard input outputstandard 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.

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.

Input 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).

Output Print a single number — the minimum difficulty of the track after removing a single hold.

Sample test(s) input 3 1 4 6 output 5 input 5 1 2 3 4 5 output 2 input 5 1 2 3 7 8 output 4 Note 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<stdio.h>
int searchmax(int a[],int n)
{
int i,max;
max=a[1];
for(i=2;i<=n;i++)
{
if(a[i]>max)
max=a[i];
}
return max;
}
int searchmin(int a[],int n)
{
int i,min;
min=a[1];
for(i=2;i<=n;i++)
{
if(a[i]<min)
min=a[i];
}
return min;
} int findmax(int a,int b)
{
if(a>b)
return a;
else
return b;
} int main()
{
int a[105],d[105],e[105],i,n,s,j,k,max;
while(scanf("%d",&n)!=EOF)
{
k=1;
max=0;
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<n;i++)
d[k++]=a[i+1]-a[i];
max=searchmax(d,n-1);
j=1;
for(i=2;i<=n-1;i++)
{
e[j++]=findmax(max,a[i+1]-a[i-1]);//找到删掉一个数后的数列中,相邻两项的差值的最大值
} printf("%d\n",searchmin(e,n-2));
}
}

  

Codeforces Round #283 (Div. 2) A的更多相关文章

  1. 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...

  2. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #283 Div.2 D Tennis Game --二分

    题意: 两个人比赛,给出比赛序列,如果为1,说明这场1赢,为2则2赢,假如谁先赢 t 盘谁就胜这一轮,谁先赢 s 轮则赢得整个比赛.求有多少种 t 和 s 的分配方案并输出t,s. 解法: 因为要知道 ...

  6. Codeforces Round #283 (Div. 2)

    A:暴力弄就好,怎么方便怎么来. B:我们知道最多加10次, 然后每次加1后我们求能移动的最小值,大概O(N)的效率. #include<bits/stdc++.h> using name ...

  7. codeforces 497c//Distributing Parts// Codeforces Round #283(Div. 1)

    题意:有n个区间[ai,bi],然后有n个人落在[ci,di],每个人能用ki次.问一种方式站满n个区间. 两种区间都用先x后y的升序排序.对于当前的区间[ai,bi],将ci值小于当前ai的全部放入 ...

  8. codeforces 497b// Tennis Game// Codeforces Round #283(Div. 1)

    题意:网球有一方赢t球算一场,先赢s场的获胜.数列arr(长度为n)记录了每场的胜利者,问可能的t和s. 首先,合法的场景必须: 1两方赢的场数不一样多. 2赢多的一方最后一场必须赢. 3最后一场必须 ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. 为my_string类创建复制构造函数copy constructor ,拷贝函数名和类同名

    为下面的my_string类创建一个复制构造函数,并将定义该类的代码提交. my_string类的定义: class my_string { char *s; public: my_string(ch ...

  2. Java常用工具类---XML工具类、数据验证工具类

    package com.jarvis.base.util; import java.io.File;import java.io.FileWriter;import java.io.IOExcepti ...

  3. 如何检查Windows网络通信端口占用

    最近本地测试jsp程序发现tomcat启动失败,无法监听8080端口,也没记得别的什么程序占用了8080端口,干脆就改成了8090端口先用着.今天找了找Windows上查看网络通信端口占用的方法. 先 ...

  4. Day 12 闭包函数,装饰器

    闭包函数 回顾: 1.函数对象:可以将定义在函数内的函数返回到全局使用.从而打破了函数层级限制 2.名称空间与作用域:作用域关系在函数定义阶段时就已经固定死了,与调用位置无关,即在任意位置调用函数都需 ...

  5. Tomcat在处理POST和GET提交方式时的字符编码问题

    部分内容参考http://yejg1212.blog.163.com/blog/static/3958206120098384327191(原作者:飞翔)  一.POST和GET请求方式的区别: 在默 ...

  6. 多行文本省略号样式失效丢失,以及控制台显示autoprefixer警告'Autoprefixer applies control comment to whole block, not to next rules.'

    问题现象   使用webpack压缩打包vue项目,遇到一个问题,文本多行显示省略号的关键css语句-webkit-box-orient: vertical;莫名其妙丢失失效了.查阅资料,有不少人提出 ...

  7. 40 最小的K个数(时间效率)

    题目描述: 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,.   测试用例: 功能测试(输入的数组中有相同的数字:输入的数组中 ...

  8. C++ STL-stack使用详解

    stack 类是容器适配器,它给予程序员栈的功能--特别是 FILO (先进后出)数据结构. 该类模板表现为底层容器的包装器--只提供特定函数集合.栈从被称作栈顶的容器尾部推弹元素. 一:头文件 #i ...

  9. omap 移植qt4.7.0

    准备: 1.Qt源码包 qt-everywhere-opensource-src-4.7.0.tar.gz 2.交叉编译器 arm-eabi-4.4.0.tar.bz2 3.触摸屏校验工具:tslib ...

  10. spring boot不同环境读取不同配置

    具体做法: 不同环境的配置设置一个配置文件,例如:dev环境下的配置配置在application-dev.properties中:prod环境下的配置配置在application-prod.prope ...