Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

天哪,这样都不wa,是不是judge出问题拉。

Posted by Iambitious at 2006-03-27 20:46:01 on Problem 1011
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator