반응형
250x250
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
- 컴퓨터그래픽스
- 우선순위큐
- 카이스트맛집
- 분리집합
- 후기
- DP
- 자바
- 대전맛집
- 안드로이드스튜디오
- 앱개발
- 몰입캠프
- computergraphics
- 카이스트
- 알고리즘
- 백준
- BFS
- html
- 프로그래머스
- glfw
- 프래그먼트
- MySQL
- node.js
- 궁동
- 몰입캠프후기
- 타입스크립트
- 어은동맛집
- 리사이클러뷰
- nodeJS
- 위상정렬
- 자바스크립트
Archives
- Today
- Total
소근소근
[백준 BOJ 2056 gold4 - 작업] 위상정렬(topological sort) C++ 본문
728x90
반응형
SMALL
백준 2056 작업
https://www.acmicpc.net/problem/2056
2056번: 작업
수행해야 할 작업 N개 (3 ≤ N ≤ 10000)가 있다. 각각의 작업마다 걸리는 시간(1 ≤ 시간 ≤ 100)이 정수로 주어진다. 몇몇 작업들 사이에는 선행 관계라는 게 있어서, 어떤 작업을 수행하기 위해
www.acmicpc.net
위상정렬 문제이다.
1516 게임개발 문제와 매우 비슷하다.
https://steptoprogrammer.tistory.com/57
[백준 BOJ 1516 gold3 - 게임 개발] 위상정렬(topological sort) C++
백준 1516 게임 개발 https://www.acmicpc.net/problem/1516 1516번: 게임 개발 첫째 줄에 건물의 종류 수 N(1 ≤ N ≤ 500)이 주어진다. 다음 N개의 줄에는 각 건물을 짓는데 걸리는 시간과 그 건물을 짓기 위해..
steptoprogrammer.tistory.com
게임개발에서는 건물 각각을 짓는데 필요한 시간을 구했다면, 여기서 가장 큰 값을 출력하는 것이 이 문제의 해답이 된다. (모든 작업을 완료하는데 걸리는 최소 시간을 구해야 하므로)
#include<iostream>
#include<string>
#include<algorithm>
#include<string.h>
#include<string>
#include<vector>
#include<queue>
using namespace std;
int N;
int indegree[10001];
vector<int> v[10001];
int period[10001];
int dab[10001];
queue <int> q;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
for (int i = 1; i <= N; i++) {
int x;
cin >> period[i];
cin >> x;
for (int j = 1; j <= x; j++) {
int k;
cin >> k;
v[k].push_back(i);
indegree[i]++;
}
}
for (int i = 1; i <= N; i++) {
if (indegree[i] == 0) q.push(i);
dab[i] = period[i];
}
while (!q.empty()) {
int top = q.front();
q.pop();
for (int i = 0; i < v[top].size(); i++) {
int next = v[top][i];
indegree[next]--;
dab[next] = max(dab[next], dab[top] + period[next]);
if (indegree[next] == 0) q.push(next);
}
}
int larg = 0;
for (int i = 1; i <= N; i++) {
if (dab[i] > larg) larg = dab[i];
}
cout << larg;
}
728x90
반응형
LIST
'Algorithm' 카테고리의 다른 글
[백준 BOJ 17218 glod5 - 비밀번호 만들기] Longest Common String (LCS) C++ (0) | 2022.01.04 |
---|---|
[백준 BOJ 3665 gold1 - 최종 순위] 위상정렬(topological sort) C++ (0) | 2021.12.31 |
[백준 BOJ 1516 gold3 - 게임 개발] 위상정렬(topological sort) C++ (0) | 2021.12.31 |
[백준 BOJ 1766 gold2 - 문제집] 위상정렬(topological sort) , 우선순위 큐(priority queue) C++ (0) | 2021.12.29 |
[백준 BOJ 1715 gold4 - 카드 정렬하기] priority queue(힙, 우선순위 큐 ) , c++ (0) | 2021.12.29 |