Codeforces Round #307 (Div. 2) A. GukiZ and Contest

原题: http://codeforces.com/contest/551/problem/A


题目大意: 给n个人, 每个人都有rank, rank最高的人是1, 同一个rank的人得分一样, 不同rank的人,得分是前边rank人数的合, 问返回的数组是什么.


分析: 我看题目是sorting, 我没sort唉. 一共rank才2000, 用个count数组记录一下, 然后从后往前(从大rank到小rank)扫数组,每次扫都取合传给下一个rank. 然后再走一般数组打印出来对应的rank就行了.

public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.readInt();
        int[] count = new int[2005];
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            int t = in.readInt();
            count[t]++;
            nums[i] = t;
        }
        int tmp = 1;
        for (int i = count.length - 1; i >=1; i--) {
            if (count[i] == 0)
                continue;
            int frq = count[i];
            count[i] = tmp;
            tmp+=frq;
        }
        for (int i = 0; i < n; i++) {
            out.print(count[nums[i]]+" ");
        }
    }