http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=29454
這題用由大至小排序後做比較好做,無條件進位要用ceil方法不過要強制轉型成(int)內部數字要浮點數
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n=scn.nextInt();
while(n--!=0){
int k=scn.nextInt(),tot=0,arr[]=new int [k],p=0;
for(int i=0;i<k;i++)
arr[i]=scn.nextInt();
Arrays.sort(arr);
tot=arr[k-1]*40/100;
for(int i=k-2,j=1;i>=0;i--,j++){
if(arr[i]!=arr[i+1])
p=(int)(Math.ceil((double)j/k*100.0));
if (p < 11)
tot += arr[i] * 40 / 100;
else if (p < 31)
tot += arr[i] * 30 / 100;
else if (p < 61)
tot += arr[i] * 20 / 100;
else if (p < 81)
tot += arr[i] * 10 / 100;
}
System.out.println(tot);
}
}
/*題目:ITSA 第46次月賽 Problem 4 貧富不均
作者:1010
時間:西元 2016 年 10 月 */
}