Skip to content

Commit aa700ad

Browse files
authored
미완성_0414
1 parent 5466f86 commit aa700ad

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package algo_ex;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.ArrayList;
7+
import java.util.HashSet;
8+
import java.util.StringTokenizer;
9+
10+
public class Main_1700_멀티탭_스케줄링_김태윤 {
11+
12+
//미완
13+
14+
/*
15+
* 27% 틀림
16+
*
17+
* 2 15
18+
* 3 2 1 2 1 2 1 2 1 3 3 3 3 3 3
19+
* 답: 2
20+
*
21+
*/
22+
public static void main(String[] args) throws IOException{
23+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
24+
StringTokenizer st = new StringTokenizer(br.readLine());
25+
26+
int N,K;
27+
N = Integer.parseInt(st.nextToken()); //멀티탭 구멍 개수
28+
K = Integer.parseInt(st.nextToken()); //전기용품 총 사용횟수
29+
30+
int arr[] = new int[K];
31+
32+
boolean multitap[] = new boolean[K+1];
33+
int elec_machine[] = new int[K+1];
34+
35+
st = new StringTokenizer(br.readLine());
36+
for(int i = 0; i<K; i++) {
37+
arr[i] = Integer.parseInt(st.nextToken());
38+
elec_machine[arr[i]]++;
39+
}
40+
41+
ArrayList<Integer> al = new ArrayList<Integer>();
42+
43+
int count = 0;
44+
int answer = 0;
45+
for(int i = 0; i<K; i++) {
46+
47+
elec_machine[arr[i]]--;
48+
49+
if(multitap[arr[i]])
50+
continue;
51+
52+
if(count<N) {
53+
54+
count++;
55+
multitap[arr[i]] = true;
56+
57+
al.add(arr[i]);
58+
59+
}else {
60+
61+
int myMax = Integer.MAX_VALUE;
62+
int index = -1;
63+
int al_index = -1;
64+
for(int j = 0; j<al.size(); j++) {
65+
int temp = al.get(j);
66+
if(elec_machine[temp] < myMax) {
67+
myMax = elec_machine[temp];
68+
index = temp;
69+
al_index = j;
70+
}
71+
}
72+
73+
multitap[index] = false;
74+
multitap[arr[i]] = true;
75+
al.remove(al_index);
76+
al.add(arr[i]);
77+
78+
answer++;
79+
}
80+
}
81+
82+
System.out.println(answer);
83+
84+
}
85+
86+
}

0 commit comments

Comments
 (0)