Queue의 정의 기본적인 자료 구조의 한가지로, 마지막에 집어 넣은 데이터가 먼저 나오는 FIFO(First In First Out)구조로 저장하는 형식을 말한다. 처음으로 Push한 값이 Pop해서 나오는 자료 구조이다. Queue 용어 Pop : Queue에 들어있는 가장 처음으로 넣어진 값을 없앤다. Push : Queue에 가장 마지막에 값을 넣는다. 백준 Queue
비정확 할 수 있음. 영어의 Stack Stack의 영어 정의는 쌓다, 쌓아 올린 더미를 뜻한다. 프로그램에서의 Stack 기본적인 자료 구조의 한가지로, 마지막에 집어 넣은 데이터가 먼저 나오는 LIFO(Last In First Out)구조로 저장하는 형식을 말한다. 마지막으로 Push한 값이 Pop해서 나오는 자료 구조이다. Stack을 구현해 보기 Queue는 Vector를 제한 한 것 이라고도 할 수 있다. 그렇기에 Vector를 제한한 class를 만들어보자. #include using namespace std; template class Stack { public: vector vec; void push(T v) { vec.push_back(v); } T top() { return vec[ve..
// 프리셋 생략 #include #include using namespace std; int k, s; int g[15]; vector able; void DFS(int Idx, int wei) { if (Idx == k) { if (wei >= 0) able[wei] = true; return; } DFS(Idx + 1, wei); DFS(Idx + 1, wei + g[Idx]); DFS(Idx + 1, wei - g[Idx]); } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> k; for (int i = 0; i > g[i]; s += g[i]; } able.resize(s + 1..
// 프리셋 생략 int n; vector arr; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i > x; arr.push_back(x); } int cnt = 0; int max_ = 0; for (int i = n - 1; i >= 0; i--) { if (arr[i] > max_) { max_ = arr[i]; cnt++; } } cout
// Preset 생략 int n; CVector inc; CVector old; pii sol_fs() { for (int i = 1; i = 1; j--) { int jindex = j - 1; int jnum = j; if (inc[jindex] != num) continue; // num을 찾음 reverse(inc.begin() + jindex, inc.begin() + index + 1); return {jindex + 1, index + 1}; } } return {-1, -1}; } pii sol(int searchFrom) { if (searchFrom == 0) return sol_fs(); else return sol_fe(); } CVector p; void try_t1(int a,..
중첩 for문을 사용해 모든 경우의수를 전부 대입 // Preset 생략 vector ables; int n; int stx = 0, sty = 0, stz = 0, sta = 0, stb = 0, stc = 0; set used; bool included(int x) { for (int y : ables) if (x == y) return true; return false; } bool allIncluded(int x) { while (x) { if (!included(x % 10)) return false; x /= 10; } return true; } int main() { cin >> n; for (int i = 0; i > x; ables.push_ba..
이번 문제는 자르고 뒤집고 하는게 많아서 python으로 풀었다. import sys n = int(sys.stdin.readline()) password = list(map(int, sys.stdin.readline().split())) # (뒤집는 시작점, 뒤집는 끝점, 두번째 왼쪽밀기의 정도)를 저장하는 리스트 ansAbles = [] for i in range(n - 1, 0, -1): Shifted = password[i : n] + password[ : i] RevSize = 0 RevStart = -1 for j in range(n - 1): if (Shifted[j] - 1 > 0 and Shifted[j + 1] == Shifted[j] - 1) or (Shifted[j] - 1 == 0..
// 프리셋 생략 int n, ans = 0; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n; // 변 // a,b,c // a c) ans++; } } cout
Preset이 600줄이 넘어서 따로 만들기로 했다. Preset은 #203 을 참고하자. BigInt를 어디서 가져왔다. 대회에 이런 문제가 나온다면 내 손으로 구현해야 하겠지만.. // [Preset 생략]... int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); string a, b; while (1) { cin >> a >> b; if (a == "0" || b == "0") break; BigInt ba(a), bb(b); if (ba > bb) swap(ba, bb); // ba < bb cout