목록C++ (74)
정화 코딩
https://www.acmicpc.net/problem/9935 #include #include #include using namespace std;int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s, bomb; cin >> s >> bomb; stack stk; int n = bomb.size(); for (char c: s) { if (c == bomb[n - 1]) { for (int i = n - 2; i >= 0; i--) { if (stk.empty()) { for (int..
https://www.acmicpc.net/problem/5639 #include #include using namespace std;vector a;void post(int s, int e) { if (s >= e) return; int idx = e; for (int i = s + 1; i a[s]) { idx = i; break; } } post(s + 1, idx); post(idx, e); cout > x) { a.push_back(x); } int n = a.size(); post(0, n);} 이 문제는 트리 구조를 만들어서 뭔갈 한다기 보다는 어떻게 하면 전위 순회..
https://www.acmicpc.net/problem/16953 #include #include #include using namespace std;int INTMAX = 1000000000;int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long a, b; cin >> a >> b; queue> q; q.emplace(a, 0); int ans = -1; while (!q.empty()) { long long x = q.front().first; int cnt = q.front().second; q.pop(); if (x..
https://www.acmicpc.net/problem/2206 #include #include #include using namespace std;int dx[] = {1, -1, 0, 0};int dy[] = {0, 0, 1, -1};int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector> g(n, vector(m)); vector> chk(n, vector(m, 0)); for (int i = 0; i > s; for (int j = 0; j > q; // {x index, y index, didBreak, coun..
https://www.acmicpc.net/problem/1987 #include #include using namespace std;int r, c;vector m;bool vst[26];int maxc = 0;int di[] = {1, -1, 0, 0};int dj[] = {0, 0, 1, -1};void dfs(int curi, int curj, int cnt) { if (cnt > maxc) maxc = cnt; for (int k = 0; k = 0 && nxti = 0 && nxtj > r >> c; m = vector(r); for (int i = 0; i > m[i]; } vst[m[0][0] - 'A'] = true; dfs(0, 0, 1); ..
https://www.acmicpc.net/problem/2448 #include #include #include using namespace std;int n;vector> ans;void recur(int si, int ni, int sj, int nj) { if (ni == 3) { ans[si][sj + 2] = '*'; ans[si + 1][sj + 1] = '*'; ans[si + 1][sj + 3] = '*'; ans[si + 2][sj] = '*'; ans[si + 2][sj + 1] = '*'; ans[si + 2][sj + 2] = '*'; ans[si + 2][sj + 3] = '*'; ..
https://www.acmicpc.net/problem/1504 #include #include #include using namespace std;int INTMAX = 1000000;int n, e, v1, v2;vector>> edge;int dijkstra(int s, int e) { vector dst(n + 1, INTMAX); priority_queue> pq; dst[s] = 0; pq.emplace(0, s); while (!pq.empty()) { int cost = -pq.top().first; int cur = pq.top().second; pq.pop(); for (auto nxt: edge[cur]) ..
https://www.acmicpc.net/problem/1967 #include #include using namespace std;vector>> g;vector vst;int maxc = 0;void dfs(int cur, int cnt) { vst[cur] = true; if (cnt > maxc) maxc = cnt; for (auto nxt: g[cur]) { if (!vst[nxt.first]) dfs(nxt.first, cnt + nxt.second); }}int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; g = vector..