목록백준 (120)
Taene's
// 일반 풀이#include using namespace std;string pel;int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> pel; int start = 0; int end = pel.length() - 1; while (start // algorithm - reverse() 사용#include #include using namespace std;string pel;int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> pel; string tmp = pel; reverse(pel.begin(), pel.end()); if (tmp == ..
https://www.acmicpc.net/problem/1325 // 범위가 [1~10,000] 이므로 배열의 설정과 초기화는 모두 10001로 해줘야 한다.#include #include using namespace std;int N, M;int ret[10001];int visited[10001];vector v[10001];int dfs(int com){ int cnt = 1; visited[com] = 1; for (auto it : v[com]) { if (visited[it]) continue; cnt += dfs(it); } return cnt;}int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N >> M..
https://www.acmicpc.net/problem/1068 #include #include using namespace std;int N, temp, root, removeNode;vector node[50];int dfs(int searchNode){ int ret = 0; int child = 0; for (auto i : node[searchNode]) { if (i == removeNode) continue; ret += dfs(i); child++; } if (!child) return 1; return ret;}int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N; for (int i = 0; i ..
https://www.acmicpc.net/problem/2636 // 자기자신이 1이라면 (adj[y][x]==1) 방문한것도 알수있고 vector에 넣고 return할 수 있다.#include #include using namespace std;int N, M;int adj[100][100];bool visited[100][100];vector> eraser;int ret, hour;int dy[] = { -1,1,0,0 };int dx[] = { 0,0,-1,1 };void OneHour(int y, int x){ visited[y][x] = 1; if (adj[y][x] == 1) { eraser.push_back({ y,x }); return; } for (int i = 0; i = N ||..
https://www.acmicpc.net/problem/14502 // 로직 1번 - 최대 64개 중 3개를 골라 벽을 세운다(조합)// 로직 2번 - 최대 64개 중 바이러스(2)가 있는 곳으로부터 바이러스를 퍼트린다(dfs, bfs)// 로직 3번 - 최대 64개 중 바이러스가 없는 안전구역(0)의 넓이를 구한다(counting)// 최대 시간복잡도는 대충 64C3 * (64 + 64) ~= 5,000,000으로 시간복잡도 천만 이하는 효율 고려하지 않고 무식하게 푼다.#include #include #include using namespace std;int N, M;int adj[8][8];bool visited[8][8];vector> wall;vector> virus;int dy[] = { -..
https://www.acmicpc.net/problem/1436 #include #include using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int i = 666; while (true) { if (to_string(i).find("666") != string::npos) n--; if (n == 0) break; i++; } cout