题目链接:http://codeforces.com/contest/496/problem/A

题目意思:给出有 n 个数的序列,然后通过删除除了第一个数和最后一个数的任意一个位置的数,求出删除这个数之后序列的最大相邻差是多少,然后删除下一个数,继续求出最大相邻差,直到删到倒数第二个数,最后从这些最大相邻差中找出最小的那个输出。例如:有序列为1 2 3 7 8,删除第二个、第三个、第四个数后得到的序列分别为:(1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8)。那么最大相邻差分别为 4,5,5,选出最小的那个就是答案 4 。

  是由于bc不会做,临时走来做 virtual 的,效果当然不是太好。。。

  可以这样想,两重循环(外循环 i ,内循环j),i 表示当前需要删除第 i 个数,j 用来删除第 i 个数之后的序列中,最大相邻差。一种很简单的办法是,

if 【i == j】   d = a[j+1] - a[i-1]

  else     d = a[j+1] - a[j]

  else 语句用得比较巧妙,例如对于 1 2 3 7 8 这个序列,如果当前删除的是3,那么序列就变成 1 2 7 8。当算到 7 这个数的时候, d = 7 - 3,虽然这个 d 并不存在(3 没有了嘛),但是算了根本不会影响结果,因为 7 - 3 绝对比 7 - 2 小!

  

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ;
const int INF = + ;
int a[maxn]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int n;
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; i++)
scanf("%d", &a[i]);
int minans = INF;
for (int i = ; i <= n-; i++)
{
int maxans = -INF;
for (int j = ; j <= n-; j++)
{
if (i == j)
maxans = max(maxans, a[j+] - a[i-]);
else
maxans = max(maxans, a[j+] - a[j]);
}
minans = min(minans, maxans);
}
printf("%d\n", minans);
}
return ;
}
												

codeforces 496A. Minimum Difficulty 解题报告的更多相关文章

  1. Codeforces Round 665 赛后解题报告(暂A-D)

    Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...

  2. Codeforces Round 662 赛后解题报告(A-E2)

    Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...

  3. Codeforces Round #277.5 解题报告

    又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...

  4. codeforces B. Simple Molecules 解题报告

    题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...

  5. 【LeetCode】1102. Path With Maximum Minimum Value 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序+并查集 优先级队列 日期 题目地址:https: ...

  6. 【LeetCode】1135. Connecting Cities With Minimum Cost 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Kruskal算法 日期 题目地址:https://l ...

  7. codeforces 591A. Wizards' Duel 解题报告

    题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...

  8. codeforces 582A. GCD Table 解题报告

    题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...

  9. codeforces 581C. Developing Skills 解题报告

    题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...

随机推荐

  1. 网络安全&信息安全&系统安全常用名词汇总

    拖库(脱裤) 隐写术 拖库(脱裤) 隐写术 拖库(脱裤) 隐写术 拖库(脱裤) 隐写术

  2. RelativeLayout布局

    RelativeLayout用到的一些重要的属性: 第一类:属性值为true或falseandroid:layout_centerHrizontal 水平居中android:layout_center ...

  3. Codeforces #270 D. Design Tutorial: Inverse the Problem

    http://codeforces.com/contest/472/problem/D D. Design Tutorial: Inverse the Problem time limit per t ...

  4. isNaN() 确认是否是数字

    isNaN(x): 当变量 x 不是数字,返回 true: 当变量 x 是其他值,(比如,1,2,3),返回false.

  5. 宿主系统为Ubuntu 14,CentOS 6.5 安装VirtualBox增强工具失败:Building the OpenGL support module[FAILED]

    安装先前的笔记:CentOS 6.3 中安装VirtualBOX增强工具失败:Building the main Guest Additions module[FAILED],执行了以下命令 #安装 ...

  6. MySQL性能优化的21条最佳经验【转】

    转载自http://www.cnblogs.com/jiaosq/p/5843437.html 今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只 ...

  7. FineUI第十三天---`列布局

    这是经典的列布局:                  <x:Panel runat=                     <Items>                      ...

  8. Joda-time是java处理时间非常棒的jar

    http://www.joda.org/joda-time/ maven: <dependency> <groupId>joda-time</groupId> &l ...

  9. cocos2d-x 内存管理浅析

    Cocos2d-x用create创建对象, 这个方法已经被引擎封装成一个宏定义了:CREATE_FUNC, 下面是这个宏定义的实现: #define CREATE_FUNC(__TYPE__) \   ...

  10. PyCharm 5 破解注册方法

    方法: 调整时间到2038年. 申请30天试用 退出pycharm 时间调整回来即可. 或者: 注册时选择 License server ,填 http://idea.lanyus.com ,然后点击 ...