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 |
所有能找到的测试数据都跑了,可最后就是出wrong answerimport java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); LinkedList<Node> ll = new LinkedList<Node>(); LinkedList<Node> result = new LinkedList<Node>(); LinkedList<Integer> a1 = new LinkedList<Integer>(); LinkedList<Integer> a2 = new LinkedList<Integer>(); LinkedList<Integer> a3 = new LinkedList<Integer>(); int listIndex = 0; long width = 0; int number = 0; long nLength = 0; long nLSum = 0; Node n; while (true) {// first while width = in.nextLong(); if (width == 0) { System.out.println(0); break; } System.out.println(width); while (true) {// read while number = in.nextInt(); nLength = in.nextLong(); nLSum = nLSum + nLength; if (number == 0 && nLength == 0) { break; } ll.add(new Node(number, nLength)); }// read while if(width>1000 && ll.get(0).nLength == width && ll.size()==1){ System.out.println(0 + " " + width); System.out.println(0 + " " + 0); ll.clear(); nLSum = 0; continue; } // 初始化 listIndex = 0; for (int i = 0; i < width; i++) { n = ll.get(listIndex); a1.add(n.number); a2.add(n.number); ll.set(listIndex, new Node(n.number, n.nLength - 1)); if (n.nLength - 1 == 0) { listIndex++; } } // 初始化 if (nLSum == width) { a3.addAll(a1); compute(result, a1, a2, a3); } else {// 正常处理的部分 while (true) { if (ll.get(listIndex).nLength > (10 * width)) { a3.clear(); for (int i = 0; i < width; i++) { n = ll.get(listIndex); a3.add(n.number); } compute(result, a1, a2, a3); change(a1, a2, a3); a3.clear(); for (int i = 0; i < width; i++) { n = ll.get(listIndex); a3.add(n.number); } n = ll.get(listIndex); ll.set(listIndex, new Node(n.number, n.nLength - 2 * width)); compute(result, a1, a2, a3); change(a1, a2, a3); n = ll.get(listIndex); result.add(new Node(0, (n.nLength / width) * width)); if (n.nLength % width == 0) { listIndex++; } else { ll.set(listIndex, new Node(n.number, n.nLength % width)); } } else { a3.clear(); for (int i = 0; i < width; i++) { n = ll.get(listIndex); a3.add(n.number); ll.set(listIndex, new Node(n.number, n.nLength - 1)); if (n.nLength - 1 == 0) { listIndex++; } } compute(result, a1, a2, a3); change(a1, a2, a3); } if (listIndex == ll.size()) break; } compute(result, a1, a2, a3);// 结尾处理 }// 正常处理的部分 long resultNumSign = result.get(0).nLength; for (int i = 1; i < result.size(); i++) { if (result.get(i - 1).number == result.get(i).number) resultNumSign = resultNumSign + result.get(i).nLength; else { System.out.println(result.get(i - 1).number + " " + resultNumSign); resultNumSign = result.get(i).nLength; } } System.out.println(result.get(result.size() - 1).number + " " + resultNumSign); System.out.println(0 + " " + 0); result.clear(); ll.clear(); a1.clear(); a2.clear(); a3.clear(); nLSum = 0; }// first while } public static void change(LinkedList<Integer> a1, LinkedList<Integer> a2, LinkedList<Integer> a3) { a1.clear(); a1.addAll(a2); a2.clear(); a2.addAll(a3); } public static void compute(LinkedList<Node> ll, LinkedList<Integer> array1, LinkedList<Integer> array2, LinkedList<Integer> array3) { LinkedList<Integer> a = new LinkedList<Integer>(); if (array1.size() <= 2) { if (array1.size() == 1) { ll.add(new Node(max(0, 0, 0, 0, 0, 0, array2.get(0) - array1.get(0), array2.get(0) - array3.get(0)), 1)); } else { ll.add(new Node(max(0, 0, 0, array2.get(0) - array1.get(0), array2.get(0) - array1.get(1), array2.get(0) - array2.get(1), array2.get(0) - array3.get(0), array2.get(0) - array3.get(1)), 1)); ll.add(new Node(max(array2.get(1) - array1.get(0), array2.get(1) - array2.get(0), array2.get(1) - array3.get(0), array2.get(1) - array1.get(1), array2.get(1) - array3.get(1), 0, 0, 0), 1)); } return; } else { a.add(max(0, 0, 0, array2.get(0) - array1.get(0), array2.get(0) - array1.get(0), array2.get(0) - array2.get(0), array2.get(0) - array3.get(0), array2.get(0) - array3.get(1))); for (int i = 1; i < array1.size() - 1; i++) { a.add(max(array2.get(i) - array1.get(i - 1), array2.get(i) - array2.get(i - 1), array2.get(i) - array3.get(i - 1), array2.get(i) - array1.get(i), array2.get(i) - array1.get(i + 1), array2.get(i) - array2.get(i + 1), array2.get(i) - array3.get(i), array2.get(i) - array3.get(i + 1))); } } int v = array1.size() - 1; a.add(max(array2.get(v) - array1.get(v - 1), array2.get(v) - array2.get(v - 1), array2.get(v) - array3.get(v - 1), array2.get(v) - array1.get(v), array2.get(v) - array3.get(v), 0, 0, 0)); long w = 1; for (int i = 1; i <= v; i++) { if (a.get(i - 1) == a.get(i)) { w++; } else { ll.add(new Node(a.get(i - 1), w)); w = 1; } } if (a.get(v - 1) == a.get(v)) { ll.add(new Node(a.get(v), w)); } else { ll.add(new Node(a.get(v), 1)); } a.clear(); } public static int max(int a, int b, int c, int d, int e, int f, int g, int h) { int[] z = { a, b, c, d, e, f, g, h }; int r = 0; for (int i = 0; i < z.length; i++) { if (z[i] < 0) z[i] = (-z[i]); if (r < z[i]) r = z[i]; } return r; } } class Node { int number; long nLength; public Node(int nB, long nBSum) { this.number = nB; this.nLength = nBSum; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator