[Huawei OD machine test real test python] Desert island survival [2023 Q2 | 200 points]

Title description

【Desert Island Survival】

There is a desert island with only two ports on the left and right, and only one bridge connecting the two ports. Now there is a group of people who need to escape from the two ports. Some people escape to the right and some escape to the left. If two people meet, then pk,
the one with greater physical strength can beat the one with smaller physical strength. If the physical strength is the same, both will perish. The winner can continue to escape and reduce the corresponding physical strength.

Enter description

A series of non-zero integers, separated by spaces. Positive numbers represent escape to the right, and negative numbers represent escape to the left.

Output description

The number of people who can finally escape

Example 1 input and output examples are for debugging only, and the background judgment data generally does not contain examples.

enter

5 10 8 -8 -5

output

2

illustrate

8 met -8 and died together. 10 met -5, won and lost five points of physical strength. The final ones who escaped were [5, 5], both escaped from the port on the right, output 2

Python code implementation:

 

Guess you like

Origin blog.csdn.net/xiao_pengjy/article/details/131930353