import java.util.Scanner;

public class Main

{

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

int n=Integer.parseInt(in.nextLine().trim());

int[] a=new int[n];

int[] b=new int[n-1];

    for(int i=0;i<n;i++)
{
a[i]=in.nextInt();
}
int min=-1;
for(int i=0;i<n;i++)
{
int k=0;
for(int j=0;j<n;j++)
{
if(i!=j)
{
b[k]=Math.abs(a[i]-a[j]);
k++;
}
}
if(min>minmax(b)||min<0)
{
min = minmax(b);
}
} System.out.println(min);
}
public static int minmax(int[] ints)
{
int min=ints[0];
for(int i=1;i<ints.length;i++)
{
if(min>ints[i])
{
min=ints[i];
}
}
return min;
}

}

CCF|最小差值|Java的更多相关文章

  1. 201712-1 最小差值 Java

    思路: 也可以不排序,最后用abs就行 import java.util.Arrays; import java.util.Scanner; public class Main { public st ...

  2. CCF CSP 201712-1 最小差值

    题目链接:http://118.190.20.162/view.page?gpid=T68 问题描述 试题编号: 201712-1 试题名称: 最小差值 时间限制: 1.0s 内存限制: 256.0M ...

  3. 奇妙的算法【10】TX--有效号码、最,小耗时、最小差值、差值输出、异或结果

    昨晚刚刚写的几道算法题,难度也还行,就是全部AC有些困难,当时第一题AC.第二题AC 60%,第四题AC 40%,第五题没有时间写完了,这个应该全部AC了:其中第三题没有写出来 1,是否存在符合规范的 ...

  4. 利用栈实现算术表达式求值(Java语言描述)

    利用栈实现算术表达式求值(Java语言描述) 算术表达式求值是栈的典型应用,自己写栈,实现Java栈算术表达式求值,涉及栈,编译原理方面的知识.声明:部分代码参考自茫茫大海的专栏. 链栈的实现: pa ...

  5. LuoguP4234_最小差值生成树_LCT

    LuoguP4234_最小差值生成树_LCT 题意: 给出一个无向图,求最大的边权减最小的边权最小的一棵生成树. 分析: 可以把边权从大到小排序,然后类似魔法森林那样插入. 如果两点不连通,直接连上, ...

  6. [Swift]LeetCode908. 最小差值 I | Smallest Range I

    Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and ...

  7. [Swift]LeetCode910. 最小差值 II | Smallest Range II

    Given an array A of integers, for each integer A[i] we need to choose either x = -K or x = K, and ad ...

  8. 2018-计算机系机试(第二批)-D-最小差值

    单点时限: 2.0 sec 内存限制: 256 MB 输入 n 个整数,输出最小差值.最小差值指所有数之间差的绝对值的最小数. 例如:3 个整数 1,2 和 6 的最小差值是 1. 输入格式 第一个数 ...

  9. leetcode-908-最小差值 I

    题目描述: 给定一个整数数组 A,对于每个整数 A[i],我们可以选择任意 x 满足 -K <= x <= K,并将 x 加到 A[i] 中. 在此过程之后,我们得到一些数组 B. 返回  ...

随机推荐

  1. 反爬统计 数据库 sql CASE

    -- 经排查日志,发现ordertest.com下的url检测,频繁<Response [403]>,Forbidden;再进一步查询数据库数据:逐日统计错误临时表test_error_t ...

  2. SQL Server 多库操作 库名.dbo.表名 出错的问题!

    SQL Server 多库操作 库名.dbo.表名 出错的问题! 数据库名不要用数字开头. 例如:343934.dbo.user 这就会出错.md a343934.dbo.user 就没问题!! 记住 ...

  3. HDU2255 奔小康赚大钱 —— 二分图最大权匹配 KM算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2255 奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    ...

  4. Ural 2003: Simple Magic(数论&思维)

    Do you think that magic is simple? That some hand-waving and muttering incomprehensible blubber is e ...

  5. bzoj4289 PA2012 Tax——点边转化

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4289 好巧妙的转化!感觉自己难以想出来... 参考了博客:https://blog.csdn ...

  6. [九省联考2018]一双木棋chess——搜索+哈希

    题目:bzoj5248 https://www.lydsy.com/JudgeOnline/problem.php?id=5248 洛谷P4363 https://www.luogu.org/prob ...

  7. 搭建gerrit服务器(apache&nginx反向代理方式)

    这段时间,想搭建一个gerrit,用于代码托管,gerrit的搭建,网上有很多种教程,但是自己按照别人的教程逐步操作,一直出现诸多问题.最头痛的就是:Configuration Error Check ...

  8. 无参数的lambda匿名函数

    lambda 语法: lambda [arg1[,arg2,arg3....argN]]:expression 1.单个参数的: g = lambda x:x*2 print g(3) 结果是6 2. ...

  9. hdu 3333(树状数组 + 离线操作)

    Turing Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. 关于centOS7的一些笔记

    使用systemctl查看 开启 关闭服务: 查看: systemctl status arcgis.server 开启: systemctl start arcgis.server 关闭: syst ...