topcoder SRM619 DIV2算法

时间:2015-06-18 12:47:27

标签: algorithm

http://community.topcoder.com/stat?c=problem_statement&pm=13112&rd=15852 http://apps.topcoder.com/wiki/display/tc/SRM+619

我不知道哪些代码行错了。而我根本无法理解。问题是为什么我的代码不起作用,意味着我没有通过测试用例No5。

5)

{ - 1,0,0,1,1,3,0,2,0,5,2,5,5,6,1,2,11,12,10,4,7,16,10 ,9,12,18,15,23,20,7,4}

{4,6,4,7,7,1,2,8,1,7,2,4,2,9,11,1,10,11,4,6,11,7,2, 8,9,9,10,10,9,8,8}

返回:27

提前致谢。

estimators_

1 个答案:

答案 0 :(得分:0)

我明白。我只检查了上级的工作类型和每个员工的工作类型。那是错的。我还必须检查每个员工的工作类型和其他员工的工作类型。问题陈述意味着“多样化”意味着所有员工的工作类型,包括上级必须是独一无二的。

public int countGood(int[] superior, int[] workType) {
    int res = 0;
    for (int i = 0; i < superior.length; i++) {
        int[] tmp = new int[101];
        tmp[workType[i]]++;

        for (int j = 0; j < superior.length; j++) {
            if (i == j) continue;

            if (superior[j] == i) {
                tmp[workType[j]]++;
            }
        }
        boolean diverse = true;
        for (int j = 0; j < 101; j++) {
            if (tmp[j] > 1) {
                diverse = false;
                break;
            }
        }
        if (diverse) res++;
    }
    return res;
}