Huawei OD Machine Test-High Performance AI Processor-2022Q4 Volume A-Py/Java/JS

A company has developed a high-performance AI processor. Each physical device has 8 AI processors, numbered 0, 1, 2, 3, 4, 5, 6, and 7.

Processors numbered 0-3 are in the same link, processors numbered 4-7 are in another link, and processors in different links cannot communicate.

Given the available processor number array array of the server and the number of processors num requested by the task, find out the chip combination that meets the following affinity scheduling principles.

Returns an empty list if no matching combination exists.

Affinity Scheduling Principles:

- If the number of application processors is 1, select the same link, the remaining number of available processors is the best, followed by the remaining 3 is the second best, then the remaining 2, and finally the remaining 4 .

- If the number of application processors is 2, the best choice is the remaining 2 processors available on the same link, followed by the remaining 4 processors, and finally the remaining 3 processors.

- If the number of processors applied for is 4, you must select 4 processors remaining available on the same link.

-If the number of application processors is 8, apply for all 8 processors of the node.

hint:

The number of processors requested by a task can only be 1, 2, 4, or 8.
Processors numbered 0-3 are on one link, processors numbered 4-7 are on another link.
The processor number is unique, and no processor with the same number exists.
enter description

The input contains two parts: array of available processor numbers and the number of processors num requested by the task.

The first line is array, and the second line is num. For example:

[0, 1, 4, 5, 6, 7]

Indicates that the processors currently numbered 0, 1, 4, 5, 6, and 7 are available. The task applies for 1 processor.

0 <= array.length <= 8

0 <= array[i] <= 7

whether in [1, 2, 4, 8]

Guess you like

Origin blog.csdn.net/miao_9/article/details/130235510