diff --git "a/13_\354\265\234\353\213\250 \352\262\275\353\241\234/\355\225\204\354\210\230/BOJ_1238.cpp" "b/13_\354\265\234\353\213\250 \352\262\275\353\241\234/\355\225\204\354\210\230/BOJ_1238.cpp" new file mode 100644 index 00000000..3457f85d --- /dev/null +++ "b/13_\354\265\234\353\213\250 \352\262\275\353\241\234/\355\225\204\354\210\230/BOJ_1238.cpp" @@ -0,0 +1,100 @@ +#include +#include +#include + +using namespace std; + +typedef pair ii; +const int INF = 1e5; + +//start 도시부터 x까지 가는 데 걸리는 소요 시간 반환 +int cityToX(int start, int n, int x, vector>& graph) { + //1. start -> x 시간 계산 + vector time1(n + 1, INF); + priority_queue, greater<>> pq1; //{ 시작점으로부터의 시간, 정점 } 내림차순 정렬 + + //시작 정점 초기화 + time1[start] = 0; + pq1.push({ 0, start }); + + while (!pq1.empty()) { + int time = pq1.top().first; + int node = pq1.top().second; + pq1.pop(); + + //이미 저장된 시간이 새로 구한 시간보다 작을 경우 넘어감 + if (time > time1[node]) { + continue; + } + + for (int i = 0; i < graph[node].size(); i++) { + int next_node = graph[node][i].first; + int next_time = time + graph[node][i].second; + + if (next_time < time1[next_node]) { + time1[next_node] = next_time; + pq1.push({ next_time, next_node }); + } + } + } + return time1[x]; +} + +//x부터 각 도시까지 가는 데 걸리는 소요 시간 벡터 반환 +vector xToCity(int n, int x, vector>& graph) { + vector time2(n + 1, INF); + priority_queue, greater<>> pq2; //{ 시작점으로부터의 시간, 정점 } 내림차순 정렬 + + //시작 정점 초기화 + time2[x] = 0; + pq2.push({ 0, x }); + + while (!pq2.empty()) { + int time = pq2.top().first; + int node = pq2.top().second; + pq2.pop(); + + //이미 저장된 시간이 새로 구한 시간보다 작을 경우 넘어감 + if (time > time2[node]) { + continue; + } + + for (int i = 0; i < graph[node].size(); i++) { + int next_node = graph[node][i].first; + int next_time = time + graph[node][i].second; + + if (next_time < time2[next_node]) { + time2[next_node] = next_time; + pq2.push({ next_time, next_node }); + } + } + } + return time2; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(NULL); cout.tie(NULL); + + //입력 + int n, m, x, a, b, t; + cin >> n >> m >> x; + + vector> graph(n + 1, vector()); //graph[시작점]: { 끝점, 소요시간 } + while (m--) { + cin >> a >> b >> t; + graph[a].push_back({ b,t }); + } + + //연산 + vector time = xToCity(n, x, graph); + int max_time = 0; + for (int i = 1; i <= n; i++) { + max_time = max(max_time, cityToX(i, n, x, graph) + time[i]); + } + + //출력 + cout << max_time; + + return 0; +} \ No newline at end of file diff --git "a/13_\354\265\234\353\213\250 \352\262\275\353\241\234/\355\225\204\354\210\230/BOJ_15685.cpp" "b/13_\354\265\234\353\213\250 \352\262\275\353\241\234/\355\225\204\354\210\230/BOJ_15685.cpp" new file mode 100644 index 00000000..b1cfc376 --- /dev/null +++ "b/13_\354\265\234\353\213\250 \352\262\275\353\241\234/\355\225\204\354\210\230/BOJ_15685.cpp" @@ -0,0 +1,75 @@ +#include +#include +#include + +using namespace std; + +const int SIZE = 101; + +//0: x 증가, 1: y 감소, 2: x 감소, 3: y 증가 +int dx[4] = { 1,0,-1,0 }; +int dy[4] = { 0,-1,0,1 }; + +void makeDragon(vector& dragon, vector>& board) { + int x = dragon[0], y = dragon[1], d = dragon[2], g = dragon[3]; + + vector dir; + dir.push_back(d); //0세대 방향 + + //1세대부터 방향 추가 + for (int i = 0; i < g; i++) { + for (int j = pow(2, i) - 1; j >= 0; j--) { + dir.push_back((dir[j] + 1) % 4); + } + } + + board[x][y] = 1; //시작 지점 표시 + for (int i = 0; i < dir.size(); i++) { + int nd = dir[i]; //다음 방향 + int nx = x + dx[nd]; + int ny = y + dy[nd]; + + board[nx][ny] = 1; + x = nx, y = ny; + } +} + +int cntSqaure(int n, vector>& dragon) { + vector> board(SIZE, vector(SIZE, 0)); + + //드래곤 커브 그리기 + for (int i = 0; i < n; i++) { + makeDragon(dragon[i], board); + } + + int cnt = 0; + for (int x = 0; x < SIZE - 1; x++) { + for (int y = 0; y < SIZE - 1; y++) { + //네 꼭짓점이 모두 드래곤 커브의 일부인 경우 횟수 증가 + if (board[x][y] && board[x + 1][y] && board[x][y + 1] && board[x + 1][y + 1]) { + cnt++; + } + } + } + return cnt; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(NULL); cout.tie(NULL); + + //입력 + int n, x, y, d, g; + cin >> n; + + vector> dragon(n, vector(4)); //dragon[i]: {x, y, d, g} + for (int i = 0; i < n; i++) { + cin >> x >> y >> d >> g; + dragon[i] = { x,y,d,g }; + } + + //연산 & 출력 + cout << cntSqaure(n, dragon); + + return 0; +} \ No newline at end of file diff --git "a/13_\354\265\234\353\213\250 \352\262\275\353\241\234/\355\225\204\354\210\230/BOJ_2458.cpp" "b/13_\354\265\234\353\213\250 \352\262\275\353\241\234/\355\225\204\354\210\230/BOJ_2458.cpp" new file mode 100644 index 00000000..82729b50 --- /dev/null +++ "b/13_\354\265\234\353\213\250 \352\262\275\353\241\234/\355\225\204\354\210\230/BOJ_2458.cpp" @@ -0,0 +1,69 @@ +#include +#include + +using namespace std; + +void floyWarshall(int n, vector>& graph) { + for (int k = 1; k <= n; k++) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + //i < k < j인 경우 i < j + if (graph[i][k] == 1 && graph[k][j] == 1) { + graph[i][j] = 1; + } + + //i > k > j인 경우 i > j + if (graph[i][k] == 2 && graph[k][j] == 2) { + graph[i][j] = 2; + } + } + } + } +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(NULL); cout.tie(NULL); + + //입력 + int n, m, a, b; + cin >> n >> m; + + vector> graph(n + 1, vector(n + 1, -1)); //graph[i][j] = 1: i가 j보다 작음, 2: i가 j보다 큼 + + //자기 자신과는 비교 못하므로 0으로 초기화 + for (int i = 1; i <= n; i++) { + graph[i][i] = 0; + } + + while (m--) { + cin >> a >> b; + graph[a][b] = 1; + graph[b][a] = 2; + } + + //연산 + floyWarshall(n, graph); + + vector cnt(n + 1, 0); //cnt[i]: i번째 학생과 비교할 수 없는 학생의 수 + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (graph[i][j] == -1) { + cnt[i]++; + } + } + } + + int result = 0; //자신의 키가 몇 번째인지 알 수 있는 학생의 수 + for (int i = 1; i <= n; i++) { + //비교할 수 없는 학생의 수가 없는 경우에만 자신의 키 순위를 정확하게 알 수 있음 + if (cnt[i] == 0) { + result++; + } + } + + //출력 + cout << result; + + return 0; +} \ No newline at end of file