codeforces 496A. Minimum Difficulty 解题报告
题目链接: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 解题报告的更多相关文章
- Codeforces Round 665 赛后解题报告(暂A-D)
Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...
- Codeforces Round 662 赛后解题报告(A-E2)
Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...
- Codeforces Round #277.5 解题报告
又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...
- codeforces B. Simple Molecules 解题报告
题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...
- 【LeetCode】1102. Path With Maximum Minimum Value 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序+并查集 优先级队列 日期 题目地址:https: ...
- 【LeetCode】1135. Connecting Cities With Minimum Cost 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Kruskal算法 日期 题目地址:https://l ...
- codeforces 591A. Wizards' Duel 解题报告
题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...
- codeforces 582A. GCD Table 解题报告
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...
- codeforces 581C. Developing Skills 解题报告
题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...
随机推荐
- php 快速排序法
function quicksort(array $arr = array()){ $len = count($arr); if ($len > 1) { $key = $arr[0]; $l_ ...
- 使用python标准库urllib2访问网页
#访问不需要登录的网页import urllib2target_page_url='http://10.224.110.118/myweb/view.jsp' f = urllib2.urlopen( ...
- [译]AngularJS Service vs Factory - Once and for all
原文: http://blog.thoughtram.io/angular/2015/07/07/service-vs-factory-once-and-for-all.html Service和Fa ...
- MongoDB MapReduce学习笔记
http://cnodejs.org/topic/51a8a9ed555d34c67831fb8b http://garyli.iteye.com/blog/2079158 MapReduce应该算是 ...
- Access应用笔记<三>
在搭了一个数据库后,买了一本<让excel飞>,里面有提及access 经过研究之后,发现access+excel的结合确实能解决我的大部分难题,并且可以做得更好. 比较好的方法是, ac ...
- Unix时间戳转换怎样在Excel批量修改?
最近在操作项目的时候碰到一个Unix时间戳转换的问题."date_time":1393031347这个是什么,你知道吗?如果你对Unix时间戳了解的话一眼就看出来.但我们本着科普的 ...
- oracle数据库启动
遇到个白痴问题,放假停电,回来时启动数据库,发现无法进入oracle管理员界面. 如下输入,但是显示的命令无效. [oracle@crm001 database]$ sqlplus / as sysd ...
- brew gradle
cat /usr/local/Library/Taps/homebrew/homebrew-versions/gradle221.rb GRADLE_HOME=/Users/temp/gradle22 ...
- HDU 2222 AC自动机模板题
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...
- iOS开发——高级篇——如何集成支付宝SDK
一.什么是支付宝 第三方支付平台 和内购非常相似内购是用户将钱付款给苹果,之后苹果分成给商户支付宝是用户将钱付款给支付宝,之后支付宝将钱转入我们的账户 使用支付宝前提购买的物品必须是和应用程序无关的. ...