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 |
Re:我的1011也是Runtime Error啊 到底是什么原因呢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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator