diff --git a/fnhid/AdHoc/1813.cpp b/fnhid/AdHoc/1813.cpp new file mode 100644 index 0000000..bea3353 --- /dev/null +++ b/fnhid/AdHoc/1813.cpp @@ -0,0 +1,28 @@ +#include +#include +using namespace std; + +int main() +{ + int n, t; + cin >> n; + vector a(51, 0); + for(int i=0;i> t; + a[t]++; + } + + for(int i=50;i>0;i--){ + if(a[i]==i) { + cout << i; + return 0; + } + } + + if(a[0]==0) cout << 0; + else cout << -1; + + return 0; + + +} \ No newline at end of file diff --git a/fnhid/PriorityQueue/1374.cpp b/fnhid/PriorityQueue/1374.cpp index aff242f..4eab974 100644 --- a/fnhid/PriorityQueue/1374.cpp +++ b/fnhid/PriorityQueue/1374.cpp @@ -17,7 +17,7 @@ using namespace std; int main() { - int n, id, answer=0; + int n, id, start, end, answer=0; priority_queue, greater> pq; @@ -25,7 +25,8 @@ int main() vector v(n); for (int i=0;i> id >> v[id-1].start >> v[id-1].end; + cin >> id >> start >> end; + v.push_back({start, end}); } sort(v.begin(), v.end(), [](const Lecture& a, const Lecture& b) diff --git a/fnhid/README.md b/fnhid/README.md index eaad859..ca1d366 100644 --- a/fnhid/README.md +++ b/fnhid/README.md @@ -1,6 +1,14 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | - |:----:|:----------:|:----------:|:-------------------------------------------:|:---------------------------------------------------:| -| 16차시 | 2025.06.25 | 다이나믹 프로그래밍 | [균형](https://www.acmicpc.net/problem/22968) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/64 | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | + |:----:|:----------:|:----------:|:------------------------------------------------------------:|:---------------------------------------------------:| +| 16차시 | 2025.06.25 | 다이나믹 프로그래밍 | [균형](https://www.acmicpc.net/problem/22968) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/64 | +| 17차시 | 2025.06.27 | KMP 알고리즘 | [찾기](https://www.acmicpc.net/problem/1786) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/67 | +| 18차시 | 2025.07.05 | 그래프 | [여러분의 다리가 되어 드리겠습니다!](https://www.acmicpc.net/problem/17352) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/73 | +| 19차시 | 2025.07.06 | 큐 | [뱀](https://www.acmicpc.net/problem/3190) | https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/74 | +| 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 | +| 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/Recursion/2448.cpp b/fnhid/Recursion/2448.cpp new file mode 100644 index 0000000..80c3465 --- /dev/null +++ b/fnhid/Recursion/2448.cpp @@ -0,0 +1,48 @@ +#include +#include + +using namespace std; + +//3*2^10 + + +vector> board(3072, vector(3072*2-1, ' ')); + +void paint(int r, int c, int n) +{ + if (n == 3) + { + board[r][c] = '*'; + board[r+1][c-1] = '*'; + board[r+1][c+1] = '*'; + board[r+2][c+1] = '*'; + board[r+2][c+2] = '*'; + board[r+2][c] = '*'; + board[r+2][c-1] = '*'; + board[r+2][c-2] = '*'; + } else + { + paint(r, c,n/2); + paint(r+n/2, c-n/2,n/2); + paint(r+n/2, c+n/2,n/2); + } +} + +int main() +{ + + int n; + cin >> n; + + + paint(0,n-1,n); + + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2 * n - 1; j++) { + cout << board[i][j]; + } + cout << '\n'; + } + +} + 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 +#include +#include + +using namespace std; + + +int main() { + cin.sync_with_stdio(false); + cin.tie(NULL); + int n, cnt=0, target, l, r, sum; + + cin >> n; + + vector v(n,0); + + for (int i = 0; i < n; i++) { + cin >> v[i]; + } + sort(v.begin(), v.end()); + + + for (int i = 0; i < n; i++) { + l=0;r=n-1; + target = v[i]; + while (l < r){ + if (l==i) {l++;continue;} + if (r==i) {r--;continue;} + sum=v[r]+v[l]; + if (sum==target) { + cnt++; + break; + } else if (sum < target) { + l++; + } else { + r--; + } + + } + } + + cout << cnt << endl; + return 0; +}