Coder Social home page Coder Social logo

bigdata's People

Watchers

 avatar  avatar

Forkers

tensyandkiya

bigdata's Issues

Solution01

import java.util.Arrays;

public class Solution01 {
public static void main(String[] args) {
int[] result = departmentRecruit(new int[]{1, 2, 1}, new int[]{67, 58, 89, 42, 27}, new int[][]{new int[]{0, 1}, new int[]{1}, new int[]{0, 2}, new int[]{2}, new int[]{0}});
System.out.println(Arrays.toString(result));
}

public static int[] departmentRecruit(int nums[], int[] scores, int[][] preference) {
    // 应聘人数
    int number = scores.length;
    // 分数和排名 i,j i表示排名,越小排名越高,arr[i][0]是原编号 arr[i][1]是分数
    int[][] scoreAndRank = new int[number][2];
    // 记录原有排序
    for (int i = 0; i < number; i++) {
        scoreAndRank[i][0] = i;
        scoreAndRank[i][1] = scores[i];
    }
    // 先算出scoreAndRank
    for (int i = 1; i < number; i++) {
        for (int j = i; j > 0; j--) {
            if (scores[j] > scores[j - 1]) {
                int temp = scores[j];
                scores[j] = scores[j - 1];
                scores[j - 1] = temp;
                // 编号顺序分数交换
                int[] tempArr = scoreAndRank[j];
                scoreAndRank[j] = scoreAndRank[j - 1];
                scoreAndRank[j - 1] = tempArr;
            }
        }
    }
    // 完成招聘计划部门数
    int num1 = 0;
    // 被雇佣人数
    int num2 = 0;
    // 被雇佣了的人 i编号 hired[i] 是否被雇佣 0否1是
    int[] hired = new int[number];
    // 开始计算
    for (int i = 0; i < nums.length; i++) {
        int num = nums[i];
        for (int j = 0; j < number; j++) {
            // 编号
            int code = scoreAndRank[j][0];
            // 人没招满 且 此人没被雇佣
            if (num > 0 && 0 == hired[code]) {
                // 判断是否对此部门有意
                for (int k = 0; k < preference[code].length; k++) {
                    if (i == preference[code][k]) {
                        num2++;
                        hired[code] = 1;
                        num--;
                        break;
                    }
                }
            }
            // 已经招满了
            if(0 == num){
                break;
            }
        }
        if(0 == num){
            num1 ++;
        }
    }
    return new int[]{nums.length - num1,number - num2};
}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.