diff --git "a/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\204\354\210\230/1238.cpp" "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\204\354\210\230/1238.cpp" new file mode 100644 index 0000000..819886a --- /dev/null +++ "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\204\354\210\230/1238.cpp" @@ -0,0 +1,76 @@ +// 파티 +#include +#include +#include +#include + +using namespace std; + +const int INF = 1e9; // 큰 값 + +vector> graph[1001]; // 인접 리스트 그래프 + +// X에서 다른 마을로 가는 최단 거리 구하기(다익스트라 알고리즘 이용) +vector dijkstra(int start, int n) { + vector dist(n + 1, INF); + priority_queue, vector>, greater>> pq; + + dist[start] = 0; + pq.push({0, start}); + + while (!pq.empty()) { + int cur_dist = pq.top().first; + int cur_node = pq.top().second; + pq.pop(); + + if (cur_dist > dist[cur_node]) continue; + + for (auto &edge : graph[cur_node]) { + int next_node = edge.first; + int weight = edge.second; + + if (dist[cur_node] + weight < dist[next_node]) { + dist[next_node] = dist[cur_node] + weight; + pq.push({dist[next_node], next_node}); + } + } + } + + return dist; +} + +// 각 마을에서 X로 가는 최단 거리 계산 +int findMax(int x, int n, vector &dist_from_x){ + int max_time = 0; + + for (int i = 1; i <= n; i++) { + if (i == x) continue; + + vector dist_to_x = dijkstra(i, n); + max_time = max(max_time, dist_to_x[x] + dist_from_x[i]); + } + + return max_time; +} + +int main() { + + // 입력 + int n, m, x; + cin >> n >> m >> x; + + for (int i = 0; i < m; i++) { + int u, v, t; + cin >> u >> v >> t; + graph[u].push_back({v, t}); + } + + // 연산 + vector dist_from_x = dijkstra(x, n); + int max_time = findMax(x, n, dist_from_x); + + // 출력 + cout << max_time << endl; + + return 0; +} diff --git "a/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\204\354\210\230/15685.cpp" "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\204\354\210\230/15685.cpp" new file mode 100644 index 0000000..118238e --- /dev/null +++ "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\204\354\210\230/15685.cpp" @@ -0,0 +1,79 @@ +// 드래곤 커브 +#include +#include +#include + +using namespace std; + +// 방향 이동 배열 (우, 상, 좌, 하) +const int dx[] = {1, 0, -1, 0}; +const int dy[] = {0, -1, 0, 1}; + +// 드래곤 커브 생성 +void generateDragonCurve(vector> &curve, int g) { + for (int generation = 0; generation < g; ++generation) { + int size = curve.size(); + pair end = curve.back(); + for (int i = size - 2; i >= 0; --i) { + int x = curve[i].first; + int y = curve[i].second; + // 회전 변환 + int newX = end.first - (y - end.second); + int newY = end.second + (x - end.first); + curve.push_back({newX, newY}); + } + } +} + +// 1x1 정사각형의 개수 계산 +int calSquare(vector> &grid){ + + int squareCount = 0; + for (int i = 0; i < 100; ++i) { + for (int j = 0; j < 100; ++j) { + if (grid[i][j] && grid[i + 1][j] && grid[i][j + 1] && grid[i + 1][j + 1]) { + ++squareCount; + } + } + } + return squareCount; + +} + +int main() { + int n; + cin >> n; + + // 101x101 격자를 초기화 (격자는 0~100까지 사용) + vector> grid(101, vector(101, false)); + + // 입력 및 드래곤 커브 생성 + for (int i = 0; i < n; ++i) { + int x, y, d, g; + cin >> x >> y >> d >> g; + + // 초기 드래곤 커브 설정 + vector> curve; + curve.push_back({x, y}); + curve.push_back({x + dx[d], y + dy[d]}); + + // 드래곤 커브 생성 + generateDragonCurve(curve, g); + + // 격자에 드래곤 커브 표시 + for (auto c : curve) { + int cx = c.first; + int cy = c.second; + if (cx >= 0 && cx <= 100 && cy >= 0 && cy <= 100) { + grid[cx][cy] = true; + } + } + } + + int squareCount = calSquare(grid); + + // 출력 + cout << squareCount << endl; + + return 0; +} diff --git "a/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\204\354\210\230/2458.cpp" "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\204\354\210\230/2458.cpp" new file mode 100644 index 0000000..cba2f77 --- /dev/null +++ "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\204\354\210\230/2458.cpp" @@ -0,0 +1,63 @@ +// 키 순서 +#include +#include +using namespace std; + +const int INF = 1e9; + +// 플로이드-워셜 알고리즘으로 모든 쌍의 관계 계산한다. +void calGraph(vector> &graph, int n){ + + for (int k = 1; k <= n; ++k) { + for (int i = 1; i <= n; ++i) { + for (int j = 1; j <= n; ++j) { + if (graph[i][k] && graph[k][j]) { + graph[i][j] = true; + } + } + } + } + +} + +// 자신의 키 순위를 알 수 있는 학생 찾아서 반환한다. +int findAnswer(vector> &graph, int n){ + int count = 0; + + for (int i = 1; i <= n; ++i) { + int smaller = 0, larger = 0; + + for (int j = 1; j <= n; ++j) { + if (graph[i][j]) smaller++; // i보다 큰 학생 수 + if (graph[j][i]) larger++; // i보다 작은 학생 수 + } + + if (smaller + larger == n - 1) { + count++; // 자신보다 크거나 작은 학생 수가 정확히 N-1이면 순위를 알 수 있음 + } + } + + return count; +} + +int main() { + int n, m; // 학생들의 수 n (2 ≤ n ≤ 500), 두 학생 키를 비교한 횟수 m (0 ≤ m ≤ n(n-1)/2) + + // 입력 + cin >> n >> m; + vector> graph(n + 1, vector(n + 1, false)); + for (int i = 0; i < m; ++i) { + int a, b; + cin >> a >> b; + graph[a][b] = true; // a < b + } + + // 연산 + calGraph(graph, n); + int answ = findAnswer(graph, n); + + // 출력 + cout << answ << endl; + + return 0; +}