Code Forces 496 A. Minimum Difficulty(水~)
来源:互联网 发布:科技绘图及数据分析 编辑:程序博客网 时间:2024/05/21 13:27
Description
给出一个长度为n的严格递增序列a,现可以从序列中删去除首尾元素外任意一个元素,问删去后的max(a[i+1]-a[i])(1<=i< n-1)最小是多少
Input
第一行为一整数n表示序列长度,第二行n个整数表示序列a
Output
输出删去任一元素后max(a[i+1]-a[i])(1<=i< n-1)
Sample Input
3
1 4 6
Sample Output
5
Solution
简单题,找到未删去元素时的max(a[i+1]-a[i])(1<=i< n)以及min(a[i+2]-a[i])(1<=i< n-1),两者比较去较大值即为答案
Code
#include<stdio.h>#define max(x,y) ((x)>(y)?(x):(y))#define min(x,y) ((x)<(y)?(x):(y))#define maxn 111int n,a[maxn],b[maxn],ans;int main(){ while(~scanf("%d",&n)) { int Max=0,Min=1111; for(int i=0;i<n;i++) { scanf("%d",&a[i]); if(i>0)Max=max(Max,a[i]-a[i-1]); if(i>1)Min=min(Min,a[i]-a[i-2]); } if(Min!=1111)Max=max(Max,Min); printf("%d\n",Max); } return 0;}
0 0
- Code Forces 496 A. Minimum Difficulty(水~)
- Codeforces 496A Minimum Difficulty(暴力)
- Codeforces 496A. Minimum Difficulty
- Code Forces 592 A. PawnChess(水~)
- A. Minimum Difficulty
- Code Forces 560 A. Currency System in Geraldion(水~)
- Code Forces 559 A. Gerald's Hexagon(水~)
- Code Forces 538 A. Cutting Banner(水~)
- Code Forces 535 A. Tavas and Nafas(水~)
- Code Forces 557 A. Ilya and Diplomas(水~)
- Code Forces 567 A. Lineland Mail(水~)
- Code Forces 581 A. Vasya the Hipster(水~)
- Code Forces 583 A. Asphalting Roads(水~)
- Code Forces 584 A. Olesya and Rodion(水~)
- Code Forces 586 A. Alena's Schedule(水~)
- Code Forces 580 A. Kefa and First Steps(水~)
- Code Forces 591 A. Wizards' Duel(水~)
- Code Forces 377 A. Maze(dfs)
- android TabHost各选项卡显示的对应内容错乱
- php 的定界符 <<<eof 的问题
- O(1) Check Power of 2
- jquery过滤性选择器
- Sqoop修改sqoop元信息实现job的增量导入
- Code Forces 496 A. Minimum Difficulty(水~)
- android的面试题
- Activity的onSaveInstanceState和onRestoreInstanceState调用的时机
- 分配内存空间
- 第四课——项目【1-5】
- android(21)(使用HttpURLConnection,HttpClient和AsyncHttpClient分别实现post和get请求数据)
- LeetCode(162) Find Peak Element
- struts2项目中forward和redirect跳转注意事项
- 有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?