P8682 [蓝桥杯 2019 省 B] 等差数列
RE是因为除以0的情况
import java.util.Arrays;
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();int[] res = new int[n+1];for(int i=1;i<=n;i++) {res[i] = sc.nextInt();}Arrays.sort(res);//求出最小公差dint MIN = Integer.MAX_VALUE;for(int i=2;i<=n;i++) {MIN = Math.min(MIN,res[i]-res[i-1]);}//解决REif(MIN == 0) {System.out.println(n);return ;}//an = a1 + (n-1)*d//由d求出nint t = res[n] - res[1];System.out.println(t/MIN+1);}
}
P8651 [蓝桥杯 2017 省 B] 日期问题
AC
P8635 [蓝桥杯 2016 省 AB] 四平方和
暴力AC