2023春-A-2 LRU-K
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
题目描述
Least Recently Used (LRU) cache scheme is to remove the least recently used frame (the one hasn't been used for the longest amount of time) when the cache is full and a new page is referenced which is not there in cache.
LRU-K is a variant of the LRU algorithm, where K represents the number of recent uses. LRU can be considered as LRU-1. Unlike LRU, the LRU-K requires the maintenance of two different queues (for historical access and cache). The data in the historical access queue is not moved to the cache queue until the data is hit K times.
For example, assuming that the length of both queues is 5, and the memory is initialized to be empty. LRU-2 is used to process the data sequence in order: 9,5,6,7,8,3,8,9,5,9,8,3,4,7,5,6. The changes of the historical access queue and the cache queue are shown in the following table:
| Data Access | Historical Aaccess Queue | Cache Queue |
|---|---|---|
| 9,5,6,7,8 | Empty | |
| 3 | 5,6,7,8,3 | |
| 8 | 5,6,7,3 | 8 |
| 9 | 5,6,7,3,9 | |
| 5 | 6,7,3,9 | 8,5 |
| 9 | 6,7,3 | 8,5,9 |
| 8 | 5,9,8 | |
| 3 | 6,7 | 5,9,8,3 |
| 4 | 6,7,4 | |
| 7 | 6,4 | 5,9,8,3,7 |
| 5 | 9,8,3,7,5 | |
| 6 | 4 | 8,3,7,5,6 |
Your job is to implement this LRU-K cache scheme.
输入格式
Each input file contains one test case. For each case, the first line gives 3 positive integers: (), () and () which are the number of hits for cache, the size of the queues (assuming both queues have the same size) and the number of referenced page ID's. Then referenced page ID's are given in the next line. A page ID is a number in the range . All the numbers in a line are separated by a space.
输出格式
For each test case, output in the first line the page ID's in the historical access queue, and in the second line, those in the cache queue. The ID's are ordered from front to rear of each queue. All the numbers in a line must be separated by 1 space, and there must be no extra space at the beginning or the end of the line. In case that a queue is empty, output - in a line instead.
样例
2 5 17
9 5 6 7 8 3 8 9 5 9 8 3 4 7 5 6 9
4 9
8 3 7 5 6
3 5 10
9 5 6 7 8 3 8 9 5 9
7 3 8 5 9
-
限制
Java (javac) 时间限制 900 ms 内存限制 256 MB
其他编译器 时间限制 200 ms 内存限制 64 MB