# Card NUmbers 给N个值为1-24的数2+2=4 则会删去两个2和一个四求剩下数的最小和

xiaoxiao2021-03-26  4

package work;

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;

public class ACardNumber {  static int data[];  static int T, minsum;

public static void main(String[] args) throws FileNotFoundException {   /* Scanner sc=new Scanner(System.in); */   Scanner sc = new Scanner(new File("src/cardnumber"));   T = sc.nextInt();   for (int t = 0; t < T; t++) {    int n = sc.nextInt();    data = new int[25];    minsum = 0;    for (int i = 0; i < n; i++) {     data[sc.nextInt()]++;    }    fnc();    for (int i = 1; i < 25; i++) {     minsum += data[i] * i;    }    System.out.println(minsum);

for (int i = 1; i < 25; i++) {     System.out.print(data[i] + " ");    }    System.out.println();

}

}

private static void fnc() {   for (int i = 24; i >= 1; i--) {    if (i % 2 != 0) {     continue;    } else {     if (data[i] > 0 && data[i / 2] > 1) {      if(data[i] >= data[i / 2] / 2){       data[i]=data[i] - data[i / 2] / 2;       data[i/2]=0;      }      else{       data[i]=0;       data[i/2]=data[i/2]-data[i]*2;      }     }    }

}  }

}

、、input

1 8 2 4 7 3 3 6 2 8

、、output

15 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0