From b4151e2079f0bd9c6ee8f267cceb83eee56e872d Mon Sep 17 00:00:00 2001 From: KimRabbert <41724458+KimRabbert@users.noreply.github.com> Date: Fri, 1 Nov 2024 14:43:30 +0900 Subject: [PATCH 1/5] =?UTF-8?q?complete=20W4=20=EC=9D=B4=EB=8F=99=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week4/KCM/[W4]_11048.cpp | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 week4/KCM/[W4]_11048.cpp diff --git a/week4/KCM/[W4]_11048.cpp b/week4/KCM/[W4]_11048.cpp new file mode 100644 index 0000000..e552d37 --- /dev/null +++ b/week4/KCM/[W4]_11048.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +using namespace std; + +vector> candyNum; +vector> isVisited; + +int candyMax(int h, int w) { + int x, y, len; + queue> q; + + q.push({ 0, 0 }); + isVisited[0][0] = true; + + while (!q.empty()) { + len = q.size(); + + for (int i = 0; i < len; i++) { + x = q.front().second; + y = q.front().first; + q.pop(); + + if (x + 1 < w && !isVisited[y][x + 1]) { + if (y == 0) { + candyNum[y][x + 1] += candyNum[y][x]; + } + else { + candyNum[y][x + 1] += max(candyNum[y][x], candyNum[y - 1][x + 1]); + } + + q.push({ y, x + 1 }); + isVisited[y][x + 1] = true; + } + + if (y + 1 < h && !isVisited[y + 1][x]) { + if (x == 0) { + candyNum[y + 1][x] += candyNum[y][x]; + } + else { + candyNum[y + 1][x] += max(candyNum[y][x], candyNum[y + 1][x - 1]); + } + + q.push({ y + 1, x }); + isVisited[y + 1][x] = true; + } + } + } + + return candyNum[h - 1][w - 1]; +} + +int main() { + int n, m; + + cin >> n >> m; + + vector v(m, 0); + candyNum.assign(n, v); + + vector v2(m, false); + isVisited.assign(n, v2); + + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) + cin >> candyNum[i][j]; + + cout << candyMax(n, m); +} \ No newline at end of file From 311ff711534d5eed622ab470b9ff1bea45e32291 Mon Sep 17 00:00:00 2001 From: KimRabbert <41724458+KimRabbert@users.noreply.github.com> Date: Sat, 9 Nov 2024 23:36:01 +0900 Subject: [PATCH 2/5] =?UTF-8?q?finish=20[W4]=20=EC=84=A0=EB=B6=84=20?= =?UTF-8?q?=EA=B5=90=EC=B0=A8=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week4/KCM/[W4]17387.cpp | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 week4/KCM/[W4]17387.cpp diff --git a/week4/KCM/[W4]17387.cpp b/week4/KCM/[W4]17387.cpp new file mode 100644 index 0000000..cdd63e1 --- /dev/null +++ b/week4/KCM/[W4]17387.cpp @@ -0,0 +1,60 @@ +#include +using namespace std; + +struct point { + long long x; + long long y; +}; + +int ccw(point a, point b, point c) { + long long s = a.x * b.y + b.x * c.y + c.x * a.y; + s -= b.x * a.y + c.x * b.y + a.x * c.y; + + if (s > 0) + return 1; + else if (s == 0) + return 0; + else + return -1; +} + +bool isCrossed(point p1, point p2, point p3, point p4) { + int p1p2, p3p4; + + p1p2 = ccw(p1, p2, p3) * ccw(p1, p2, p4); + p3p4 = ccw(p3, p4, p1) * ccw(p3, p4, p2); + + if (p1p2 == 0 && p3p4 == 0) { + if (p3.x == p2.x && p1.x == p4.x) + return p3.y <= p2.y && p1.y <= p4.y; + + return p3.x <= p2.x && p1.x <= p4.x; + } + + return p1p2 <= 0 && p3p4 <= 0; +} + +int main() { + point p1, p2, p3, p4; + point tmp; + int result; + + cin >> p1.x >> p1.y >> p2.x >> p2.y; + cin >> p3.x >> p3.y >> p4.x >> p4.y; + + if (p1.x > p2.x || (p1.x == p2.x && p1.y > p2.y)) { + tmp = p1; + p1 = p2; + p2 = tmp; + } + + if (p3.x > p4.x || (p3.x == p4.x && p3.y > p4.y)) { + tmp = p3; + p3 = p4; + p4 = tmp; + } + + result = isCrossed(p1, p2, p3, p4); + + cout << result; +} \ No newline at end of file From 693889ae8d1d15c566b434f63e779bbf29bd7a82 Mon Sep 17 00:00:00 2001 From: KimRabbert <41724458+KimRabbert@users.noreply.github.com> Date: Sun, 10 Nov 2024 00:24:17 +0900 Subject: [PATCH 3/5] =?UTF-8?q?complete=20[W4]=20=EB=A1=9C=EB=B4=87=20?= =?UTF-8?q?=EC=8B=9C=EB=AE=AC=EB=A0=88=EC=9D=B4=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week4/KCM/[W4]_2174.cpp | 130 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 week4/KCM/[W4]_2174.cpp diff --git a/week4/KCM/[W4]_2174.cpp b/week4/KCM/[W4]_2174.cpp new file mode 100644 index 0000000..00d88dc --- /dev/null +++ b/week4/KCM/[W4]_2174.cpp @@ -0,0 +1,130 @@ +#include +#include +using namespace std; + +class RobotSimulation { + struct robot { + int x; + int y; + int dir; + }; + int w, h; + vector> land; + vector info; +public: + void setLand(int, int); + void inputRobot(int); + void inputCommand(int); +}; + +void RobotSimulation::setLand(int x, int y) { + w = x; + h = y; + + vector v(x + 2, -1); + land.push_back(v); + + v.assign(x + 2, 0); + v[0] = -1; + v[x + 1] = -1; + for (int i = 0; i < y; i++) + land.push_back(v); + + v.assign(x + 2, -1); + land.push_back(v); +} + +void RobotSimulation::inputRobot(int n) { + int x, y; + char dir; + robot r; + + info.assign(n + 1, r); + + for (int i = 1; i <= n; i++) { + cin >> x >> y >> dir; + + land[y][x] = i; + + info[i].x = x; + info[i].y = y; + + if (dir == 'E') + info[i].dir = 0; + else if (dir == 'N') + info[i].dir = 1; + else if (dir == 'W') + info[i].dir = 2; + else + info[i].dir = 3; + } +} + +void RobotSimulation::inputCommand(int n) { + int robotNum, rep; + char cmd; + int dx[4] = { 1, 0, -1, 0 }; + int dy[4] = { 0, 1, 0, -1 }; + int tx, ty; + int curX, curY; + int landInfo; + + for (int i = 0; i < n; i++) { + cin >> robotNum >> cmd >> rep; + + if (cmd == 'L') { + info[robotNum].dir = (info[robotNum].dir + rep) % 4; + } + else if (cmd == 'R') { + info[robotNum].dir = (info[robotNum].dir - rep + 100) % 4; + } + else { + curX = info[robotNum].x; + curY = info[robotNum].y; + + tx = curX; + ty = curY; + + for (int j = 0; j < rep; j++) { + tx += dx[info[robotNum].dir]; + ty += dy[info[robotNum].dir]; + + landInfo = land[ty][tx]; + + if (landInfo == -1) { + cout << "Robot " << robotNum << " crashes into the wall"; + return; + } + else if (landInfo != 0) { + cout << "Robot " << robotNum << " crashes into robot " << landInfo; + return; + } + } + + land[ty][tx] = robotNum; + land[curY][curX] = 0; + + info[robotNum].x = tx; + info[robotNum].y = ty; + } + } + + cout << "OK"; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(0); cout.tie(0); + + int A, B, N, M; + RobotSimulation rs; + + cin >> A >> B; + + rs.setLand(A, B); + + cin >> N >> M; + + rs.inputRobot(N); + rs.inputCommand(M); +} \ No newline at end of file From b0573406752a579c7d65d6238c87efba27437e82 Mon Sep 17 00:00:00 2001 From: KimRabbert <41724458+KimRabbert@users.noreply.github.com> Date: Mon, 11 Nov 2024 01:46:46 +0900 Subject: [PATCH 4/5] =?UTF-8?q?complete=20[W4]=20=EB=8B=AD=EC=8B=B8?= =?UTF-8?q?=EC=9B=80=20=ED=8C=80=20=EC=A0=95=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week4/KCM/[W4]_1765.cpp | 88 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 week4/KCM/[W4]_1765.cpp diff --git a/week4/KCM/[W4]_1765.cpp b/week4/KCM/[W4]_1765.cpp new file mode 100644 index 0000000..165bbe5 --- /dev/null +++ b/week4/KCM/[W4]_1765.cpp @@ -0,0 +1,88 @@ +#include +#include +using namespace std; + +class teamMaking { + vector team; + vector isVisited; + vector>> graph; + int numOfTeam; +public: + teamMaking(int n = 0) { + vector> v; + graph.assign(n + 1, v); + + numOfTeam = n; + + for (int i = 0; i <= n; i++) { + team.push_back(i); + } + + isVisited.assign(n + 1, false); + } + void inputGraph(int); + int makeTeam(); + void dfs(int, int, char); +}; + +void teamMaking::inputGraph(int n) { + char cn; + int p, q; + + for (int i = 0; i < n; i++) { + cin >> cn >> p >> q; + + graph[p].push_back({ q, cn }); + graph[q].push_back({ p, cn }); + } +} + +int teamMaking::makeTeam() { + int teams = numOfTeam; + + for (int i = 1; i <= teams; i++) { + if (i == team[i]) { + isVisited.assign(teams + 1, false); + isVisited[i] = true; + dfs(i, i, 'F'); + } + } + + return numOfTeam; +} + +void teamMaking::dfs(int cur, int root, char con) { + for (int i = 0; i < graph[cur].size(); i++) { + if (root != team[graph[cur][i].first] && graph[cur][i].second == con) { + if (team[graph[cur][i].first] != graph[cur][i].first) { + team[cur] = team[graph[cur][i].first]; + numOfTeam--; + } + else { + team[graph[cur][i].first] = root; + isVisited[graph[cur][i].first] = true; + numOfTeam--; + + dfs(graph[cur][i].first, root, 'F'); + } + } + else if (con == 'F' && graph[cur][i].second == 'E') { + dfs(graph[cur][i].first, root, 'E'); + } + } +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(0); cout.tie(0); + + int n, m; + + cin >> n; + teamMaking tmk(n); + + cin >> m; + tmk.inputGraph(m); + + cout << tmk.makeTeam(); +} \ No newline at end of file From 8cade902adfb9e38de1acd5ffa01742583d2a412 Mon Sep 17 00:00:00 2001 From: KimRabbert <41724458+KimRabbert@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:24:31 +0900 Subject: [PATCH 5/5] =?UTF-8?q?complete=20[W5]=20=EC=8B=9C=ED=97=98=20?= =?UTF-8?q?=EA=B0=90=EB=8F=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week5/KCM/[W5]_13458.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 week5/KCM/[W5]_13458.cpp diff --git a/week5/KCM/[W5]_13458.cpp b/week5/KCM/[W5]_13458.cpp new file mode 100644 index 0000000..9ec6815 --- /dev/null +++ b/week5/KCM/[W5]_13458.cpp @@ -0,0 +1,30 @@ +#include +#include +using namespace std; + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(0); cout.tie(0); + + int N; + int B, C; + long long sum = 0; + + cin >> N; + vector examinee(N); + + for (int i = 0; i < N; i++) + cin >> examinee[i]; + + cin >> B >> C; + + sum += N; + for (int i = 0; i < N; i++) { + examinee[i] -= B; + + if (examinee[i] > 0) + sum += (examinee[i] - 1) / C + 1; + } + + cout << sum; +} \ No newline at end of file