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 |
Tags
- VR
- 유니온 파인드
- Unreal Engine 5
- 브루트포스
- 유니티
- 다이나믹 프로그래밍
- 트리
- 재귀
- 투 포인터
- XR Interaction Toolkit
- DFS
- ue5
- 수학
- c++
- 백준
- 정렬
- 다익스트라
- 백트래킹
- 누적 합
- 그리디 알고리즘
- 구현
- 스택
- 자료구조
- Team Fortress 2
- BFS
- 알고리즘
- 그래프
- 문자열
- 시뮬레이션
- 우선순위 큐
Archives
- Today
- Total
1일1알
백준 17952번 과제는 끝나지 않아! C++ 본문
https://www.acmicpc.net/problem/17952
17952번: 과제는 끝나지 않아!
성애는 이번 학기에 전공을 정말 많이 듣는다. 이로 인해 거의 매일을 과제를 하면서 보내고 있다. 그런데도 과제가 줄어들 기미가 보이지 않는데, 바로 분단위로 과제가 추가되고 있기 때문이
www.acmicpc.net
최근에 했던 과제를 꺼내서 하기에는 스택이 적합한 것 같아서 스택을 사용해서 풀었다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
struct Task {
int score;
int time;
};
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
int ans = 0;
Task* currTask = nullptr;
stack<Task*> jobStack;
for (int i = 0; i < n; i++) {
int val;
cin >> val;
if (val == 1) {
int a, t;
cin >> a >> t;
if (currTask == nullptr) {
currTask = new Task({ a,t });
if (--currTask->time == 0) {
ans += currTask->score;
currTask = nullptr;
}
}
else {
jobStack.push(currTask);
currTask = new Task({ a,t });
if (--currTask->time == 0) {
ans += currTask->score;
currTask = nullptr;
}
}
}
else {
if (currTask == nullptr) {
if (jobStack.empty()) continue;
currTask = jobStack.top();
jobStack.pop();
}
if (--currTask->time == 0) {
ans += currTask->score;
currTask = nullptr;
}
}
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 11758번 CCW C++ (0) | 2023.02.01 |
---|---|
백준 24445번 알고리즘 수업 - 너비 우선 탐색 2 C++ (0) | 2023.01.31 |
백준 1240번 노드사이의 거리 C++ (0) | 2023.01.29 |
백준 13414번 수강신청 C++ (0) | 2023.01.28 |
백준 14921번 용액 합성하기 C++ (0) | 2023.01.27 |