文章目录

  • 一、B. Honest Coach
  • 总结

一、B. Honest Coach

本题链接:B. Honest Coach

题目

B. Honest Coach

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output

There are n athletes in front of you. Athletes are numbered from 1 to n from left to right. You know the strength of each athlete — the athlete number i has the strength si.

You want to split all athletes into two teams. Each team must have at least one athlete, and each athlete must be exactly in one team.

You want the strongest athlete from the first team to differ as little as possible from the weakest athlete from the second team. Formally, you want to split the athletes into two teams A and B so that the value |max(A)−min(B)| is as small as possible, where max(A) is the maximum strength of an athlete from team A, and min(B) is the minimum strength of an athlete from team B.

For example, if n=5 and the strength of the athletes is s=[3,1,2,6,4], then one of the possible split into teams is:

first team: A=[1,2,4],
second team: B=[3,6].
In this case, the value |max(A)−min(B)| will be equal to |4−3|=1. This example illustrates one of the ways of optimal split into two teams.

Print the minimum value |max(A)−min(B)|.

Input
The first line contains an integer t (1≤t≤1000) — the number of test cases in the input. Then t test cases follow.

Each test case consists of two lines.

The first line contains positive integer n (2≤n≤50) — number of athletes.

The second line contains n positive integers s1,s2,…,sn (1≤si≤1000), where si — is the strength of the i-th athlete. Please note that s values may not be distinct.

Output
For each test case print one integer — the minimum value of |max(A)−min(B)| with the optimal split of all athletes into two teams. Each of the athletes must be a member of exactly one of the two teams.

Example
input
5
5
3 1 2 6 4
6
2 1 3 2 4 3
4
7 9 3 1
2
1 1000
3
100 150 200
output
1
0
2
999
50

Note
The first test case was explained in the statement. In the second test case, one of the optimal splits is A=[2,1], B=[3,2,4,3], so the answer is |2−2|=0.

本博客给出本题截图

题意:把一个数组分成两个数组A和B,求|max(A)−min(B)|的最小值

AC代码

#include <iostream>
#include <algorithm>using namespace std;const int N = 55;int a[N];int main()
{int t;cin >> t;while (t -- ){int n;cin >> n;for (int i = 0; i < n; i ++ ) cin >> a[i];sort(a, a + n);int res = a[1] - a[0];for (int i = 1, j = 2; j < n; i ++, j ++ )res = min(res, a[j] - a[i]);cout << res << endl;}return 0;
}

总结

水题,不解释

Honest Coach相关推荐

  1. Honest Coach CodeForces - 1360B(简单贪心)

    题目: 把所给的数组分成a和b两个子数组(元素不重复使用),令a数组的的最大值和b数组的最小值的差最小,并输出. 题意: There are n athletes in front of you. A ...

  2. Codeforces Round #644 (Div. 3)(A-E)

    这场的A-E都是水题,就简单记录一下吧. Minimal Square CodeForces - 1360A 思路:我们令b=max(a,b),a=min(a,b). 如果b>=2*a的话,最终 ...

  3. Codeforces Round #644(Div. 3) A-H

    A - Minimal Square 题意 给两个完全一样的矩形(平行且不重叠) 求能覆盖两个矩形的最小正方形的面积 思路 只有两种摆放方式 将两个矩形上下并列或者左右并列 得到的新图形 长或者宽是之 ...

  4. [CTO札记]高效能辅导(Coach)转摘

    昨天的<与下属共同成长的'16字辅导真言'>谈的是管理中的'下属辅导'.蔡啸的一篇Blog(高效Coach培训整理(一)),记录了<高效能辅导>培训课程的心得.鉴于内容精要,图 ...

  5. 不合法的媒体文件 id_注意!伦敦男孩、DKNY、Coach、地素... 这些品牌的服装,抽检不合格...

    此次质量抽查包括36家企业销售的54个奢侈服装品牌,不合格项目涉及pH值.附件抗拉强力.色牢度.可萃取重金属等强制性标准. 其中,BOY London的一款开衫连帽卫衣耐干摩擦色牢度不达标,另一款卫衣 ...

  6. coach和mentor,教练和导师的区别

    今天晚上我向我的妹妹介绍了我最近在公司参加的教练相关的培训计划,我妹妹是一位在希腊圣域拥有超过十年青铜圣斗士教学经验的白银圣斗士,在圣域担任导师工作,负责青铜圣斗士的mentoring. 我用我两都熟 ...

  7. 蔻驰和mk哪个更大牌_mk和coach哪个好?mk和coach包包是一个档次吗?

    说到包包,mk和coach可谓是轻奢界的两大巨头了.因此,两个品牌的包包不可避免的会被经常拿来作比较.那么,从各个角度来讲mk和coach那款包包更好呢?这两款包包又有哪些本质上的区别呢? mk和co ...

  8. 【英语学习】【Daily English】U11 Work L02 Just be honest

    文章目录 Word Preparation workload:工作量 first thing tomorrow:明天的第一件事 just be honest:实话实说 You sound stress ...

  9. COACH与得物App达成官方合作 未来计划提供专供款商品

    5月9日消息,奢侈品牌COACH宣布与得物App达成官方合作.COACH官方入驻得物App后,除了提供包括手袋.皮具.配饰在内的专柜同步款外,未来还计划为得物App上的用户提供专供款商品. 据介绍,此 ...

最新文章

  1. MATLAB信号包络的提取
  2. 使用Golang搭建gRPC服务提供给.NetCore客户端调用
  3. configparser操作配置文件
  4. printf 指针地址_c语言对指针的理解
  5. 阿里云ubuntu mysql_Ubuntu下安装MySQL(阿里云服务器)
  6. 以太网峰会:网络管理员已成濒危职业
  7. 如何添加二级标题_怎样给Word文档添加目录?
  8. Rainbond 5.0正式发布, 支持对接管理已有Kubernetes集群...
  9. 小菜鸟一步步打造图书馆外挂之十三:用户编辑界面的实现
  10. hive 的drop table命令出错
  11. Bailian2793 孙子问题【扩展欧几里德算法+中国剩余定理】
  12. 第六章_循环神经网络(RNN)
  13. java-----抽象类与接口
  14. UNIX高级环境编程(11)进程控制(Process Control)- 进程快照,用户标识符,进程调度...
  15. vissim免修改时间工具_视频剪辑工具premiere最基础使用教程
  16. linux 内核PCI驱动总结记录
  17. Excel合并单元格排序
  18. crt格式证书转pem格式证书
  19. 获取 ProgramData 文件夹路径
  20. Android夜间模式最佳实践

热门文章

  1. Elasticsearch 中的 Guice
  2. matlab与c/c++混合...,matlab与c/c++ 混合编程之 MCR | 学步园
  3. 两台W7系统的电脑,A电脑可以ping通B电脑,B电脑ping不通A电脑。
  4. 用Google来翻译你的网页
  5. IdentityServer4实现Token登录以及权限控制
  6. 心血来潮 回味人生
  7. Go实现简单的TCP服务端客户端通信(有黏包)
  8. 【Python】模块详解/如何安装模块的方法
  9. 小白学习ppt---珞珈carlos
  10. 系统分析员考试复习笔记-6:第六章:系统的配置与性能评价