https://www.nowcoder.com/acm/contest/107/F

Link: https://www.nowcoder.com/acm/contest/107/F
Source: Niuke.com

In the process of learning Operating System, Glory encountered such a problem. Now there is a memory with a size that can hold N pages. The content in the hard disk is divided into M pages, which are identified by 1~M. At the beginning, there is no memory in the memory. For any page, the next user will request Q pages, you need to design a replacement algorithm to minimize the number of page faults. A page fault is when a user requests a page with a certain number, but the page is not in memory. After a page fault occurs, you must transfer the corresponding page in the hard disk into the memory. If the memory is full, you need to replace a page in the current memory.

Enter description:

Multiple sets of data, please process until the end of the input.
For each set of data, the first row is three integers N, M, Q (0 < N, M, Q <= 50000)
The number of Q in the next line represents the page number requested by the user.

Output description:

For each set of data, output a number that represents the minimum number of page faults.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324589663&siteId=291194637