11652: 카드
2022. 9. 29. 02:01ㆍC언어/백준
자료구조
브론즈 4
https://www.acmicpc.net/problem/11652
-결과
-코드
#include <stdio.h>
int main() {
int cnt, n, m;
int i, j, k;
int arr[100] = { 0, };
scanf("%d", &cnt);
for (i = 0; i < cnt; i++) {
scanf("%d %d", &n, &m);
int ans = 1;
int front = 0;
int max = 0;
for (j = 0; j < n; j++) {
scanf("%d", &arr[j]);
}
while (1) {
for (k = 0; k < n; k++) {
if (arr[k] > max) max = arr[k];
}
while (arr[front] != max) {
front = (front + 1) % n;
}
if (front == m) {
break;
}
arr[front] = 0;
front = (front + 1) % n;
max = 0;
ans++;
}
printf("%d\n", ans);
}
return 0;
}
-풀이
이 문제는 원형 큐를 이용해서 풀어야 한다.
'C언어 > 백준' 카테고리의 다른 글
2675: 문자열 반복 (0) | 2022.09.24 |
---|---|
1764: 듣보잡 (0) | 2022.09.24 |
18258: 큐 2 (0) | 2022.09.24 |
3052: 나머지 (0) | 2022.09.24 |
1158: 요세푸스 문제 (0) | 2022.09.24 |