목록Algorithm/C++ (148)
cgy12306
// https://www.acmicpc.net/problem/17219 // 비밀번호 찾기 #include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N, M; string id, pw; map account; cin >> N >> M; for (int i = 0; i > id >> pw; account[id] = pw; } for (int i = 0; i > site; cout
// https://www.acmicpc.net/problem/17626 // Four Squares #include #include using namespace std; int dp[50001] = { 0, }; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; for (int i = 1; i
// https://www.acmicpc.net/problem/1012 // 유기농 배추 #include #include using namespace std; bool map[51][51]; int T, M, N, K, X, Y, cnt = 0; int dx[] = { 0,0,-1,1 }; int dy[] = { 1,-1,0,0 }; void dfs(int x, int y) { map[x][y] = false; for (int i = 0; i = M || tmpy >= N) continue; if (!map[tmpx][tmpy]) continue..
// https://www.acmicpc.net/problem/2606 // 바이러스 // reference by wizely #include #include using namespace std; void dfs(vector &edge, vector &infested, int start) { infested[start] = true; for (auto next : edge[start]) { if (!infested[next]) { dfs(edge, infested, next); } } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int V, E, from, to, cnt = 0; cin >> V >> E; vecto..
// https://www.acmicpc.net/problem/1654 // 랜선 자르기 #include #include using namespace std; long long K, N, lan[10001], low, high, mid, res; bool check(long long length) { int cnt = 0; for (int i = 0; i = N) return true; else return false; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> K >> N; for (int i = 0; i < K; i..
// https://www.acmicpc.net/problem/2331 // 반복수열 #include #include #include using namespace std; int calc(int A, int P) { int num = 0, tmp = 1; while (A) { for (int i = 0; i > A >> P; D.push_back(A)..
// https://www.acmicpc.net/problem/11724 // 연결 요소의 개수 #include #include using namespace std; int N, M, u, v; void dfs(vector &e, int start, vector &visit) { visit[start] = true; for (auto next : e[start]) { if (!visit[next]) { dfs(e, next, visit); } } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // N : 정점의 개수, M : 간선의 개수 cin >> N >> M; vector e(N + 1); vector visit(..
// https://www.acmicpc.net/problem/1978 // 소수 찾기 #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; bool arr[1001] = { 0, }; cin >> N; arr[0] = 1; arr[1] = 1; for (int i = 2; i a; if (!arr[a]) cnt++; } cout