andy6804tw
10/9/2017 - 9:45 AM

ITSA 第57次月賽 Problem 5. The Job Scheduling Problem

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=38008

這題要先暸解Shortest jop first(sjf) 意思是花費最小的工作時間先執行 所以這題必須要排序,之後陣列走訪依序加上等待時間

import java.math.BigInteger;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		
		Scanner scn=new Scanner(System.in);
		int n=Integer.parseInt(scn.nextLine());
		while(n--!=0) {
			String s[]=scn.nextLine().split(" ");
			int arr[]=new int [Integer.parseInt(s[0])],tot=0,num=0,pre=0;
			for(int i=0;i<arr.length;i++)
				arr[i]=Integer.parseInt(s[i+1]);
			Arrays.sort(arr);
			for(int i=0;i<arr.length;i++) {
				num+=pre;
				tot+=num;
				pre=arr[i];
			}
			System.out.println(tot);
		}	
	}
/*題目:Problem 5. The Job Scheduling Problem
    作者:1010
    時間:西元 2017 年10 月 */
}