Algorithm(218)
-
[BOJ] 6198번 : 옥상 정원 꾸미기
1. problem : https://www.acmicpc.net/problem/6198 2. solution 1 :#include using namespace std;int main(void) { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; stack s; long long ans = 0; while (N--) { int height; cin >> height; while (!(s.empty()) && s.top() ans를 while문안에서 더해주다가 틀렸다. 이때가 성립할 때는 감소하다가 증가하는 포인트가 있어야 성립한다. 따라서, while문 밖으로 ans를 빼주어야 한다.
2024.08.07 -
[BOJ] 5430번 : AC
1. problem :https://www.acmicpc.net/problem/5430 2. solution 1 :#include using namespace std;void parse(string& input, deque& D) { int cur = 0; for (int i = 1; i + 1 & d) { cout > T; while (T--) { deque D; int rev = 0; string op; bool isWrong = false; int n; string input; cin >> op; cin >> n; cin >> input; parse(input, D); for (char c : op) { if (c == 'R') { rev = 1 - rev; } ..
2024.08.07 -
[BOJ] 1021번 : 회전하는 큐
1. problem :https://www.acmicpc.net/problem/1021 2. solution 1 :#include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int ans = 0; int N, M; cin >> N >> M; deque D; for (int i = 1; i > x; deque dq2(D); deque dq3(D); while (true) { if (dq2.front() != x) { count2++; dq2.push_back(dq2.front()); dq2.pop_front(); } else { dq2.pop_front(); brea..
2024.08.07 -
[BOJ] 10866번 : 덱
1. problem :https://www.acmicpc.net/problem/10866 2. solution 1 :#include using namespace std;const int MX = 1000005;int dat[2 * MX + 1];int head = MX, tail = MX; void push_front(int x) { dat[--head] = x;}void push_back(int x) { dat[tail++] = x;}int pop_front() { if (head == tail) return -1; return dat[head++];}int pop_back() { if (head == tail) return -1; return dat[--tail];}int front() { if (h..
2024.08.07 -
[BOJ] 2164번 : 카드2
1. problem : https://www.acmicpc.net/problem/2164 2. solution 1 :#include using namespace std;int main(void) { ios::sync_with_stdio(0); cin.tie(0); queue Q; int N; cin >> N; for (int i = 1; i 1) { Q.pop(); // 첫 번째 요소를 제거 int temp = Q.front(); // 두 번째 요소를 temp에 저장 Q.pop(); // 두 번째 요소 제거 Q.push(temp); // 두 번째 요소를 큐의 뒤로 이동 } cout
2024.08.07 -
[BOJ] 10845 : 큐
1. problem : https://www.acmicpc.net/problem/10845 2. solution 1 :#include using namespace std;const int MX = 100001;int dat[MX];int fir = 0, fin = 0;void push(int x) { dat[fin++] = x;}int pop() { if (fir == fin) return -1; return dat[fir++];}int empty() { return (fir == fin) ? 1 : 0;}int size() { return fin - fir;}int front() { if (fir == fin) return -1; return dat[fir];}in..
2024.08.07