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

Re:我的1011也是Runtime Error啊 到底是什么原因呢

Posted by qq609248709 at 2010-08-10 12:38:13 on Problem 1001
In Reply To:我的也是Runtime Error啊 到底是什么原因呢 Posted by:sdojjy at 2010-07-21 21:48:36
我这是1011题的,也是Rutime Error 不知道什么原因
public class Sticks1011 {
	private static int n; // 木棒的个数

	private static int[] s; // 每条木棒的长度

	private static int sum; // 木棒加起来的总长度

	private static int min; // 可能的最小长度

	private static int[] visited;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while ((n = in.nextInt()) != 0) {
			s = new int[n];
			visited = new int[n];
			Arrays.fill(visited, 0);
			sum = 0;
			for (int i = 0; i < n; i++) {
				s[i] = in.nextInt();
				sum += s[i];
			}
			Arrays.sort(s);
			min = s[n - 1];
			while (min <= sum) {
				if (sum % min == 0) {
					if (search(min, min, n)) {
						System.out.println(min);
						break;
					}
				}
				min++;
			}
		}
	}
	public static boolean search(int len, int remains_len, int num) {
		if (remains_len == 0 && num == 0)
			return true;
		if (remains_len == 0)
			remains_len = len;
		for (int i = 0; i < n; i++) {
			if (visited[i] == 0) {
				visited[i] = 1;
				if (search(len, remains_len - s[i], num - 1))
					return true;
				visited[i] = 0;

				if (s[i] == remains_len || len == remains_len)
					break;

			}
		}
		return false;
	}
}

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