← 返回 amazon 的题目列表Surviving Processes in Robot Conflicts
类型:online_judge
Problem Description
There are n independent processes, each supported by robots[i] number of robots. These processes compete with each other, where each minute a conflict occurs between two randomly chosen processes. Your task is to find out which inventory processing processes can survive to the end in at least one possible conflict order.
Conflict Rules
The process with more robots will absorb the process with fewer robots and gain their robot count.
If both processes have the same number of robots, one is randomly selected to win and gain the other's robot count.
Input
Integer n, the number of processes.
Integer array robots of length n, where robots[i] represents the number of robots for process i.
Output
Return an integer array representing the process numbers (1-indexed) that can survive to the end in at least one possible conflict order.
Example
Input: n = 5, robots = [1, 6, 2, 7, 2]
Output: [2, 4]
Explanation
Process 2 can survive to the end through a series of merger operations as follows:
Process 2 absorbs process 1, changes to [0, 7, 2, 7, 2]
Process 2 absorbs process 3, changes to [0, 9, 0, 7, 2]
Process 2 absorbs process 4, changes to [0, 16, 0, 0, 2]
Process 2 absorbs process 5, changes to [0, 18, 0, 0, 0]
Process 4 can also survive to the end:
Process 4 absorbs process 1, changes to [1, 6, 2, 8, 2]
Process 4 absorbs process 3, changes to [1, 6, 0, 10, 2]
Process 4 absorbs process 2, changes to [1, 0, 0, 16, 2]
Process 4 absorbs process 5, changes to [1, 0, 0, 18, 0]
Therefore, the answer is [2, 4].
Example
Input
5
1 6 2 7 2