HUAWEI OD machine test - number sequence ratio size (Java & JS & Python)

topic description

Two people A and B play a game of number ratio. Before the game, two people will get two numbers sequences of the same length. The two numbers sequences are different, and the numbers in them are random.

A and B each select a number from the number sequence for size comparison. The winner gets 1 point, and the loser deducts 1 point. If they are equal, their respective scores remain unchanged. Used numbers need to be discarded.

Find the maximum score that A can win against B.

enter description

The first number of the input data represents the length N of the number sequence, followed by two number sequences of length N.

output description

A's possible win over B's maximum score

Remark

  1. Here it is required to calculate the maximum score that A may win against B. It may be assumed that A knows the number sequence of B, and B always chooses the number first and expresses it clearly.
  2. A greedy strategy can be adopted. If you can win, you must win, and if you want to lose, try to minimize the loss.

Example

enter 3
4 8 10
3 6 4
output 3
illustrate

The first digit of the input data indicates that the length of the digital sequence is 3,

Guess you like

Origin blog.csdn.net/qfc_128220/article/details/131185797