package work;
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;
public class Aceil { static int data[]; static boolean used[]; static int minsec;
public static void main(String[] args) throws FileNotFoundException { /* Scanner sc=new Scanner(System.in); */ Scanner sc = new Scanner(new File("src/ceil")); int T = sc.nextInt(); for (int t = 0; t < T; t++) { int N = sc.nextInt(); data = new int[257]; used = new boolean[257]; for (int n = 0; n < N; n++) { data[sc.nextInt()]++; } dfs(0); // for (int i = 1; i < 257; i++) { if (data[i] != 0) { System.out.print(i +":"+data[i] +" "); } } System.out.println(); // System.out.println(minsec); } }
private static void dfs(int sec) { minsec=sec; if (check()) { return; } for (int i = 128; i >= 1; i--) { if (data[i] > 1) { data[2 * i] += data[i] / 2; if (data[i] % 2 == 0) {data[i] = 0;} else {data[i] = 1;} } } dfs(sec+1); }
private static boolean check() { boolean temp=true; for (int i = 0; i < data.length; i++) { if (data[i] > 1) { temp=false; break; } } return temp; }
}
、、input
1 6 1 2 4 2 1 16
、、output
2:1 8:1 16:1 2