标签:static ref system family get 绝对值 参考资料 蓝桥杯 imp
目录
48
具体代码如下:
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Main { public static long n, m, temp; public static ArrayList<Long> list = new ArrayList<Long>();//存放输入的数 public static ArrayList<Long> result = new ArrayList<Long>(); public void getResult() { Collections.sort(list); for(int i = 0, j = list.size() - 1;m > 0;) { if(m >= 2) { long a1 = list.get(i) * list.get(i + 1); long a2 = list.get(j) * list.get(j - 1); if(a2 > a1) { temp *= list.get(j); j--; m--; } else { temp *= a1; i = i + 2; m = m - 2; } } else { if(m == 1) { temp *= list.get(j); j--; m--; } } } result.add(temp); } public static void main(String[] args) { Main test = new Main(); Scanner in = new Scanner(System.in); int t = in.nextInt(); while(t > 0) { t--; n = in.nextLong(); m = in.nextLong(); temp = 1; list.clear(); for(int i = 0;i < n;i++) { long a = in.nextLong(); list.add(a); } test.getResult(); } for(int i = 0;i < result.size();i++) System.out.println(result.get(i)); } }
参考资料:
标签:static ref system family get 绝对值 参考资料 蓝桥杯 imp
原文地址:http://www.cnblogs.com/liuzhen1995/p/6786053.html