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

不懂了 为什么显示的是answer error 本地测试挺好的 sort方法自己实现的也是不行呀

Posted by zhangye1 at 2017-10-01 14:52:21 on Problem 1009
package learn_1000_1099;


import java.util.*;

public class Main_1009 {

    private static class Record {

        private int[][] data;
        private int pair;
        private int totalPoints;
        private int width;

        public Record(int[][] data, int pair, int totalPoints, int width) {
            this.data = data;
            this.pair = pair;
            this.width = width;
            this.totalPoints = totalPoints;
        }

        public void result() {
            int position = 0;
            List<int[]> tempOutput = new ArrayList<int[]>();
            for (int i = 0; i < pair; ++i) {
                int row = position / width;
                int col = position % width;
                for (int r = row - 1; r <= row + 1; ++r) {
                    for (int c = col - 1; c <= col + 1; ++c) {
                        int tempPosition = r * width + c;
                        if (tempPosition < 0 || tempPosition >= totalPoints)
                            continue;
                        int[] positionPair = new int[]{tempPosition, getMaxPixel(tempPosition)};
                        tempOutput.add(positionPair);
                    }
                }
                position += data[i][1];
            }

            tempOutput.sort(new Comparator<int[]>() {
                @Override
                public int compare(int[] o1, int[] o2) {
                    return o1[0] - o2[0];
                }
            });

            System.out.println(width);
            int index = 0;
            tempOutput.add(new int[]{totalPoints, -1});
            for (int i = 0; i < tempOutput.size(); ++i) {
                if (tempOutput.get(index)[1] == tempOutput.get(i)[1]) {
                    continue;
                }
                System.out.println(tempOutput.get(index)[1] + " " +
                        (tempOutput.get(i)[0] - tempOutput.get(index)[0]));
                index = i;
            }

            System.out.println("0 0");
        }

        private int getMaxPixel(int tempPosition) {
            int row = tempPosition / width;
            int col = tempPosition % width;
            int max = 0;
            int pixel = getPixelByPosition(tempPosition);

            for (int r = row - 1; r <= row + 1; ++r) {
                for (int c = col - 1; c <= col + 1; ++c) {

                    int p = r * width + c;

                    if (r < 0 || c < 0 || c >= width || p >= totalPoints || p == tempPosition || p < 0) {
                        continue;
                    }
                    int impossibleMax = Math.abs((pixel - getPixelByPosition(p)));
                    if (impossibleMax > max) {
                        max = impossibleMax;
                    }
                }
            }
            return max;
        }


        private int getPixelByPosition(int position) {
            int sum = 0;
            for (int i = 0; i < pair; ++i) {
                int nextSum = data[i][1] + sum;
                if (sum <= position && position < nextSum) {
                    return data[i][0];
                }
                sum = nextSum;
            }
            return 0;
        }


    }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Record> list = new LinkedList<Record>();
        int width;
        width = scanner.nextInt();
        while (width != 0) {
            int[][] data = new int[1000][2];
            int pair = 0;
            int totalPoints = 0;

            int pixel;
            int pixelNum;

            pixel = scanner.nextInt();
            pixelNum = scanner.nextInt();
            while (!(pixel == 0 && pixelNum == 0)) {
                data[pair][0] = pixel;
                data[pair][1] = pixelNum;
                ++pair;

                totalPoints += pixelNum;
                pixel = scanner.nextInt();
                pixelNum = scanner.nextInt();
            }
            list.add(new Record(data, pair, totalPoints, width));
            width = scanner.nextInt();
        }
        for (Record r : list) {
            r.result();
        }
        System.out.print("0");
    }
}

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