Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions 0224LJH/202511/05 BOJ 멀티탭 스케줄링.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

static int size,totalLen,count;
static int[] arr;
static HashSet<Integer> set = new HashSet<>();

public static void main(String[] args) throws IOException {
init();
process();
print();
}

private static void init() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));;
StringTokenizer st = new StringTokenizer(br.readLine());
//이거 그냥 lfd 라는 페이지 교체 알고리즘을 쓰면 된다!
size = Integer.parseInt(st.nextToken());
totalLen = Integer.parseInt(st.nextToken());
arr = new int[totalLen];

st = new StringTokenizer(br.readLine());
for (int i = 0; i <totalLen; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}


}

private static void process() {
count = 0;


for (int i = 0; i < totalLen; i++) {
if (set.size() < size) {
set.add(arr[i]);
continue;
}
if (set.contains(arr[i])) continue;

int target = -1;
int targetDistance = 0;
for (int num: set) {
int distance = 10000;
for (int j = i; j < totalLen; j++) {
if (arr[j] == num) {
distance = j-i;
break;
}
}
if (targetDistance < distance) {
target = num;
targetDistance = distance;
}
}

count++;
set.remove(target);
set.add(arr[i]);

}


}



private static void print() {
System.out.println(count);
}
}


```