From 915be225f921be7c8f419551b672adf2e1a13e1f Mon Sep 17 00:00:00 2001 From: Fnhid Date: Fri, 1 Aug 2025 20:24:27 +0900 Subject: [PATCH 1/2] 2025-08-01 --- fnhid/README.md | 3 +- fnhid/Simulation/8972.cpp | 204 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 fnhid/Simulation/8972.cpp diff --git a/fnhid/README.md b/fnhid/README.md index 229e1c0..ca1d366 100644 --- a/fnhid/README.md +++ b/fnhid/README.md @@ -9,5 +9,6 @@ | 20차시 | 2025.07.12 | 우선순위 큐 | [강의실](https://www.acmicpc.net/problem/1374) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/80 | | 21차시 | 2025.07.14 | 투 포인터 | [좋다](https://www.acmicpc.net/problem/1253) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/83 | | 22차시 | 2025.07.18 | 애드 혹 | [논리학 교수](https://www.acmicpc.net/problem/1813) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/86 | -| 23차시 | 2025.07.23 | 재귀 | [별 찍기 - 11](https://www.acmicpc.net/problem/2448) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/90 | +| 23차시 | 2025.07.23 | 재귀 | [별 찍기 - 11](https://www.acmicpc.net/problem/2448) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/90 | +| 24차시 | 2025.08.01 | 시뮬레이션 | [미친 아두이노](https://www.acmicpc.net/problem/8972) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/92 | \ No newline at end of file diff --git a/fnhid/Simulation/8972.cpp b/fnhid/Simulation/8972.cpp new file mode 100644 index 0000000..8df8e43 --- /dev/null +++ b/fnhid/Simulation/8972.cpp @@ -0,0 +1,204 @@ +#include +#include +#include + +class CrazyArdu; +using namespace std; + +#define R first +#define S second + +typedef pair Pos; +int dr[10]={0,1,1,1,0,0,0,-1,-1,-1}; +int ds[10]={0,-1,0,1,-1,0,1,-1,0,1}; // [0] is dummy + + + +class Ardu +{ +protected: + Pos cur; + +public: + Ardu(Pos p) + { + this->cur = p; + } + + Pos getPos() + { + return this->cur; + } +}; + +class JongSuArdu : public Ardu { +private: + int moveCnt; + Pos boardPos; +public: + JongSuArdu(const Pos& initP, const Pos& boardP) : Ardu(initP) + { + this->moveCnt = 0; + this->boardPos.R = boardP.R; + this->boardPos.S = boardP.S; + } + + int getMoveCnt(){ + return moveCnt; + } + + void move(char idx) + { + char d = idx - '0'; + if (cur.R < boardPos.R && cur.R >= 0) + cur.R = cur.R + dr[d]; + if (cur.S < boardPos.S && cur.S >= 0) + cur.S = cur.S + ds[d]; + if (idx != 5) + moveCnt++; + } +}; + +class CrazyArdu : public Ardu +{ +private: + vector dirDist; + + void updateDirDist(JongSuArdu j) + { + Pos jPos = j.getPos(); + for (int i=1;i<5;i++) + { + int cr = cur.R + dr[i]; // 1~4 + int cs = cur.S + ds[i]; + dirDist[i] = abs(cr - jPos.R) + abs(cs - jPos.S); + } + + for (int i=6;i<=9;i++) + { + int cr = cur.R + dr[i]; // 6~9 + int cs = cur.S + ds[i]; + dirDist[i] = abs(cr - jPos.R) + abs(cs - jPos.S); + } + }; + + +public: + CrazyArdu(const Pos& initP) : Ardu(initP) + { + dirDist = vector(10, 9999); + } + void move(JongSuArdu j) + { + updateDirDist(j); + int minIdx=0, minVal=999999; + for (int i=0;i<10;i++) + { + if (minVal>dirDist[i]) + { + minIdx = i; + minVal = dirDist[i]; + } + } + cur.R=cur.R+dr[minIdx]; + cur.S=cur.S+ds[minIdx]; + } + +}; +int main() +{ + int c, r; + string cmdStr; + + vector crazyArdus; + JongSuArdu* jongSu = nullptr; + + cin >> r >> c; + + + for (int i=0;i> tmp; + if (tmp == 'R') crazyArdus.push_back(new CrazyArdu(Pos{i,j})); + else if (tmp == 'I') jongSu = new JongSuArdu(Pos{i,j}, Pos{r, c}); + } + } + + + cin >> cmdStr; + + for (char cmd: cmdStr) + { + jongSu->move(cmd); + for (auto crazyArdu: crazyArdus) // JongsuCollision check + { + if (crazyArdu->getPos() == jongSu->getPos()) + { + cout << "kraj " << jongSu->getMoveCnt()<< "\n"; + + delete jongSu; + for (auto *ard : crazyArdus) delete ard; + return 0; + } + } + + map> posMap; + + for (auto crazyArdu: crazyArdus) // crazyArdu moves && JongsuCollision check && pre for crazyarducollisioncheck + { + crazyArdu->move(*jongSu); + posMap[crazyArdu->getPos()].push_back(crazyArdu); + if (crazyArdu->getPos() == jongSu->getPos()) + { + cout << "kraj " << jongSu->getMoveCnt()<< "\n"; + + delete jongSu; + for (auto *ard : crazyArdus) delete ard; + return 0; + } + } + + // crazyArdu Collision check + vector survivedCrazyArdu; + + for (auto& p : posMap) + { + if (p.second.size() == 1) + survivedCrazyArdu.push_back(p.second[0]); + else + { + for (auto* v : p.second) delete v; + } + } + crazyArdus = survivedCrazyArdu; + + + } + + + // print + + vector> board(r, vector(c+1,'.')); + + board[jongSu->getPos().R][jongSu->getPos().S] = 'I'; + + for (auto crazyArdu: crazyArdus) + board[crazyArdu->getPos().R][crazyArdu->getPos().S] = 'R'; + + + for (int i=0;i Date: Wed, 27 Aug 2025 20:41:00 +0900 Subject: [PATCH 2/2] 2025-08-27 --- fnhid/Math/1002.cpp | 28 ++++++++++++++++++++++++++++ fnhid/README.md | 3 ++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 fnhid/Math/1002.cpp diff --git a/fnhid/Math/1002.cpp b/fnhid/Math/1002.cpp new file mode 100644 index 0000000..797ed3b --- /dev/null +++ b/fnhid/Math/1002.cpp @@ -0,0 +1,28 @@ +#include + +using namespace std; + +int main() { + int t, x1, y1, r1, x2, y2, r2; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2; + int d = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); + int rsum = (r1 + r2) * (r1 + r2); + int rdiff = (r1 - r2) * (r1 - r2); + if (d == 0) { + if (r1 == r2) { + cout << -1 << "\n"; + } else { + cout << 0 << "\n"; + } + } else if (d > rsum || d < rdiff) { + cout << 0 << "\n"; + } else if (d == rsum || d == rdiff) { + cout << 1 << "\n"; + } else { + cout << 2 << "\n"; + } + } + return 0; +} diff --git a/fnhid/README.md b/fnhid/README.md index ca1d366..216494c 100644 --- a/fnhid/README.md +++ b/fnhid/README.md @@ -10,5 +10,6 @@ | 21차시 | 2025.07.14 | 투 포인터 | [좋다](https://www.acmicpc.net/problem/1253) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/83 | | 22차시 | 2025.07.18 | 애드 혹 | [논리학 교수](https://www.acmicpc.net/problem/1813) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/86 | | 23차시 | 2025.07.23 | 재귀 | [별 찍기 - 11](https://www.acmicpc.net/problem/2448) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/90 | -| 24차시 | 2025.08.01 | 시뮬레이션 | [미친 아두이노](https://www.acmicpc.net/problem/8972) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/92 | +| 24차시 | 2025.08.01 | 시뮬레이션 | [미친 아두이노](https://www.acmicpc.net/problem/8972) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/92 | +| 25차시 | 2025.08.27 | 수학 | [터렛](https://www.acmicpc.net/problem/1002) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/96 | \ No newline at end of file