-->
当前位置:首页 > 题库

PROGRAMMING:Banker's algorithm -- apply for resources

Luz5年前 (2021-05-10)题库458
Input n processes (n < = 100), and M resources (m < = 100), initialize the total number of various resources, and the allocation of resources at t0. For example, suppose there are five processes {P 0, p 1, P 2, P 3, P 4} and three types of resources {a, B, C} in the system. The number of resources is 10, 5, 7 respectively. The resource allocation diagram at t0 is as follows:
![ QQ browser screenshot 20201108222915. PNG] (~ / 173aa4b8-bf8f-4138-9ded-4eaf55f0ab43. PNG)
Input the process of applying for resources and the number of various types of resources to determine whether to allocate. If assigned, output "can find the safe sequence, which can be assigned“ And output the system state after allocation. If not, the output cannot find the security sequence and will not be assigned“ And output the current system state.
###Input format:
In the first line, enter the number of processes n, in the second line, enter the number of resource classes m, in the third line, enter the total number of resource classes M. in the following N lines, enter the name of each process, the maximum demand of the process for M resources, and the allocated resources. In the last line, enter the name of the application process and the number of resources to be applied for.
###Output format:
If assigned, output "can find the safe sequence, which can be assigned“ And output the system state after allocation.
If not, give the reasons for not distributing:
1. If the name of the input process is incorrect, the "output" check does not have this process“ And output the current system state.
2. If the number of resources applied is greater than the maximum demand, the output demand is unreasonable and will not be allocated“ And output the current system state.
3. If the number of resources applied is greater than the remaining resources, the remaining resources will not be allocated“ And output the current system state.
4. If the security sequence cannot be found, output "cannot find the security sequence and will not be assigned“ And output the current system state.
###Input sample 1:
Here is a set of inputs. For example:
```in
five
three
10 5 7
P0 7 5 3 0 1 0
P1 3 2 2 2 0 0
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
P4 4 3 2 0 0 2
P1 1 0 2
```
###Output sample 1:
The corresponding output is given here. For example:
```out
Secure sequences can be found and assigned.
name max allocation need available
P0 7 5 3 | 0 1 0 | 7 4 3 | 2 3 0
P1 3 2 2 | 3 0 2 | 0 2 0 |
P2 9 0 2 | 3 0 2 | 6 0 0 |
P3 2 2 2 | 2 1 1 | 0 1 1 |
P4 4 3 2 | 0 0 2 | 4 3 0 |
```
###Input sample 2:
Here is a set of inputs. For example:
```in
five
three
10 5 7
P0 7 5 3 0 1 0
P1 3 2 2 2 0 0
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
P4 4 3 2 0 0 2
P5 1 0 2
```
###Output sample 2:
The corresponding output is given here. For example:
```out
There is no such process.
name max allocation need available
P0 7 5 3 | 0 1 0 | 7 4 3 | 3 3 2
P1 3 2 2 | 2 0 0 | 1 2 2 |
P2 9 0 2 | 3 0 2 | 6 0 0 |
P3 2 2 2 | 2 1 1 | 0 1 1 |
P4 4 3 2 | 0 0 2 | 4 3 0 |
```






answer:If there is no answer, please comment