1 等差数列 没思路 混了9%
2 货车 18% 不知道原因,不晓得什么情况没考虑
大佬指点一下啊,心态快炸了..........
Scanner in = new Scanner(System.in); String first = in.nextLine(); String second = in.nextLine(); String[] fir = first.split(" "); int count = Integer.valueOf(fir[0]); int cars = Integer.valueOf(fir[1]); String[] sec = second.split(" "); int[] a = new int[count]; for (int i = 0; i < count; i++) { a[i] = Integer.valueOf(sec[i]); } Arrays.sort(a); int count0 = 0; int index = 0; for (int i = 0; i < count; i++) { if(a[i] == 0){ count0++; index = i; } } long qian = 0; int zz = 0; if(count0 >= cars - 1){ for(int i = index + 1; i < count; i++){ qian += a[i]; } qian = qian * qian; zz = count - (index + 1); } else { long qian1= 0; long qian2 = 0; if(count0 == 0){ for (int i = 0; i < cars - 1; i++){ qian1 += a[index + i] * a[index + i]; } for(int i = cars - 1; i<count; i++){ qian2 += a[i]; } zz = count - ( cars -1); }else { cars = cars - count0; for (int i = 0; i < cars - 1; i++){ qian1 += a[index + 1 + i] * a[index + 1 + i]; } for(int i = index + 1 + cars -1; i< count; i++){ qian2 += a[i]; } zz = count - (index + 1 + cars -1); } qian = qian1 + qian2* qian2; //zz = count - (index + 1 + cars -1); } System.out.println(qian + " " + zz);
全部评论
(15) 回帖