Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
天哪,这样都不wa,是不是judge出问题拉。import java.io.FileNotFoundException; import java.io.FileReader; import java.util.Arrays; import java.util.Scanner; public class Main { /** * @param args */ static int[] stick; static int n; static int max; static int min; public static void main(String[] args) throws FileNotFoundException { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); n = in.nextInt(); while(n != 0){ stick = new int[n]; int sum = 0; max = -1; min = 51; for(int i = 0; i < n; i++){ stick[i] = in.nextInt(); sum += stick[i]; max = Math.max(max, stick[i]); min = Math.min(min, stick[i]); } System.out.println("不是吧");//请看这个地方,这样都TLE Arrays.sort(stick); for(int average = 1; average <= sum; average++){ if(sum % average == 0){ if(max > average || (max < average && max + min > average)) continue; int[] state = new int[sum / average]; if(ok(state, sum / average, 0, average)){ System.out.println(average); break; } } } n = in.nextInt(); } } public static boolean ok(int[] state, int count, int index, int average){ boolean res = false; if(index == n) return true; for(int i = 0; i < count; i++){ if(state[i] + stick[index] <= average){ if(state[i] + min > average) return false; state[i] += stick[index]; if(ok(state, count, index + 1, average)){ res = true; break; } else{ state[i] -= stick[index]; } } if(state[i] == 0){ break; } } return res; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator