반응형
✏️ 문제 링크
https://www.acmicpc.net/problem/1700
✏️ 문제 설명 (더보기 클릭 👆🏻)
✏️ 문제 풀이
1. 멀티탭에 이미 꼽혀 있는 경우:
1-1. 계속 진행
2. 멀티탭에 꼽혀있지 않은 경우
2-1. 멀티탭이 꽉 차지 않은 경우
2-1-1. 바로 꼽는다
2-2. 멀티탭이 꽉 차있는 경우
2-2-1. plug별 가장 나중에 사용될 것 혹은 아예 사용되지 않을 아이를 고른후 뽑느다.
✏️ 문제 코드
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
vector<int> used(101, false);
vector<int> order;
vector<int> plug;
int N, K;
int get_min(int idx){
//return index for removing in plug
int r=0;
for(int i=0; i<plug.size(); i++){
int t=100;
for(int j=idx; j<order.size(); j++){
if(order[j]==plug[i]){// 가장 나중에 사용될 아이
t=j;
break;
}
}
// 발견되지 않은 경우
if(t==100) return i;
else r=max(r, t);
}
for(int i=0; i<plug.size();i++){
if(plug[i]==order[r])
return i;
}
}
int main()
{
int answer=0;
cin>>N>>K;
for(int i=0; i<K; i++){
int in; cin>>in;
order.push_back(in);
}
for(int i=0; i<order.size(); i++){
int cur=order[i];
//이미 사용중인 경우
if(used[cur]){
continue;
}else{
//플러그가 꽉찬 경우
if(plug.size()>=N){
answer++;
int low=get_min(i);
used[plug[low]]=false;
plug.erase(plug.begin()+low);
}
plug.push_back(cur);
used[cur]=true;
}
}
cout<<answer<<"\n";
return 0;
}
⭐ if feedback and question : comment please⭐
반응형
'Algorithm 💫 > Problem Solving' 카테고리의 다른 글
[백준] 1916: 최소비용 구하기/ 다익스트라 / C++ ⭐ (0) | 2021.09.15 |
---|---|
[백준] 1806번: 부분합/ C++ ⭐ (0) | 2021.09.14 |
[백준] 1062번: 가르침 / C++ (0) | 2021.09.14 |
[백준] 2504번: 괄호의 값 / C++ (0) | 2021.09.14 |
[백준] 15666번: N과 M(12) - 주어진 N개의 수로 M 길이의 중복되지 않는 수열 만들기 (조합, 같은 수 여러 번 선택 가능) (0) | 2021.09.13 |
댓글