문제
https://www.acmicpc.net/problem/1700
해설
조건 적용하는것이 생각보다 까다로웠던 문제
입력이 적어서 3중 for문을 사용해 해결했음
코드
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, k, ret;
int main()
{
cin >> n >> k;
vector<int> list(k), mul(n, 0);
for (int i = 0; i < k; i++)
{
cin >> list[i];
}
for (int i = 0; i < k; i++)
{
int flag = 0;
for (int j = 0; j < n; j++)
{
if (mul[j] == 0)
{
mul[j] = list[i];
flag = 1;
break;
}
else if (mul[j] == list[i])
{
flag = 1;
break;
}
}
if (flag == 0)
{
int last_mul = 0;
int last_cnt = 0;
for (int x = 0; x < n; x++)
{
for (int z = i + 1; z < k; z++)
{
if (list[z] == mul[x])
{
if (z > last_cnt)
{
last_cnt = z;
last_mul = x;
}
break;
}
if (z == k - 1)
{
last_cnt = z + 1;
last_mul = x;
}
}
}
mul[last_mul] = list[i];
ret++;
}
}
cout << ret;
return 0;
}
|
cs |
'백준 알고리즘(C++)' 카테고리의 다른 글
| 백준 14889번 스타트와 링크 ( C++ ) (0) | 2024.09.05 |
|---|---|
| 백준 17144번 미세먼지 안녕! ( C++ ) (1) | 2024.09.04 |
| 백준 13144번 List of Unique Numbers ( C++ ) (0) | 2024.09.04 |
| 백준 3273번 두 수의 합 ( C++ ) (1) | 2024.09.03 |
| 백준 1644번 소수의 연속합 ( C++ ) (0) | 2024.09.03 |