Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프로그래밍언어
- 재귀
- 자료구조
- 다이나믹프로그래밍
- 안드로이드
- 병합정렬
- 선택정렬
- 수학
- 버블정렬
- 정수론
- 동적계획법
- 백준
- 백트래킹
- 프로그래밍
- 선택알고리즘
- 자바
- java
- 기수정렬
- 힙정렬
- C++
- Median of Medians
- 정렬
- 알고리즘
- SNS
- 코딩테스트
- 삽입정렬
- 퀵정렬
- 계수정렬
- 동적프로그래밍
- DP
Archives
- Today
- Total
MODE::CREATIVE
[백준][c++] 1966번: 프린터 큐 본문
https://www.acmicpc.net/problem/1966
문제 해석
- 큐를 이용한 우선순위 구하기
알고리즘 분류
- 자료구조
- 큐
풀이
- 순서(num)와 우선순위(prioty)를 가진 class를 큐에 저장하고
- 순회하며 제일 우선순위가 큰지 검사
코드
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
int n, m, t;
class Num {
public:
int num;
int prioty;
Num(int a, int b) : num(a), prioty(b){};
};
void solution() {
cin >> n >> m;
queue<Num> q;
for (int i=0; i<n; i++) {
int prioty;
cin >> prioty;
q.push(Num(i, prioty));
}
int count = 0;
while (!q.empty()) {
bool flag = true; //우선순위가 가장 큰가?
Num current = q.front();
queue<Num> tempQ = q;
while (!tempQ.empty()) {
Num temp = tempQ.front();
tempQ.pop();
if(temp.prioty > current.prioty) {
flag = false;
break;
}
}
q.pop();
if (flag) {
count++;
if(current.num == m) {
cout << count << "\n";
return;
}
}
else
q.push(current);
}
}
int main() {
cin >> t;
for(int i = 0; i<t; i++) solution();
return 0;
}
'BOJ' 카테고리의 다른 글
[백준][c++] 1783번: 병든 나이트 (1) | 2024.10.03 |
---|---|
[백준][c++] 1929번: 소수 구하기 (1) | 2024.10.02 |
[백준][c++] 2108번: 통계학 (2) | 2024.10.01 |
[백준][c++] 2193번: 이친수 (0) | 2024.09.22 |
[백준][c++] 2579번: 계단 오르기 (0) | 2024.09.22 |