본문 바로가기

Algorithm

(49)
FIRETRUCKS #include #include #include using namespace std; #define MAX_V 1001 #define INF 99999 vector truckLocations; vector fireLocations; // first - adj vertex, second - cost vector adj[MAX_V]; vector dijkstraModified(); int main() { int caseNum; cin >> caseNum; for (int cIter = 0; cIter < caseNum; cIter++) { truckLocations.clear(); fireLocations.clear(); for (int i = 0; i < MAX_V; i++) { adj[i].clear()..
ROUTING #include #include #include using namespace std; #define MAX_V 10000 #define INF 99999 vector adj[MAX_V]; vector dijkstra(int v, int src); int main() { int caseNum; cin >> caseNum; for (int cIter = 0; cIter > n >> m; int start, end; float cost; for (int i = 0; i > start >> end >> cost; adj[start].push_back(make_pair(end, cost)); } vector dist ..
HANOI4B #include #include #include #include #include using namespace std; #define PILLAR_COUNT 4 #define DISK_NUM_INFINITE 999999 #define PILLAR_1_MASK 0xFFF0000000000000 #define PILLAR_2_MASK 0x000FFF0000000000 #define PILLAR_3_MASK 0x000000FFF0000000 #define PILLAR_4_MASK 0x000000000FFF0000 unsigned int diskCnt = 0; struct State { unsigned long long disks; unsigned int minDiskIdx[PILLAR_COUNT]; State(..
CHILDRENDAY #include #include #include #include #include using namespace std; int append(int here, int edge, int mod); string gifts(vector digits, int n, int m); int main() { int caseNum = 0; cin >> caseNum; for (int cIter = 0; cIter > allowedDigits >> n >> m; vector digits; while (allowedDigits != 0) { digits.push_back(allowedDigits % 10); a..
SORTING GAME #include #include #include #include #include using namespace std; int bfs(vector& perm); int main() { int caseNum; cin >> caseNum; cin.ignore(); for (int cIter = 0; cIter > n; vector items; int input_item; for (int nIter = 0; nIter > input_item; items.push_back(input_item); } int shortest_distance = bfs(items); cout
GALLERY #include #include #include #include using namespace std; bool **gAdj; int galleryNum = 0, hallwayNum = 0; vector visited; const int UNWATCHED = 0; const int WATCHED = 1; const int INSTALLED = 2; int installCount = 0; int dfsForInstall(int here); int installCamera(); int main() { int caseNum = 0; cin >> caseNum; cin.ignore(); for (int cIter = 0; cIter < caseNum; cIter++) { #pragma region READ INP..
DICTIONARY #include #include #include #include #include using namespace std; vector adj; vector visited; vector phase; // 위상 vector words; void makeGraph(); vector topologicalSort(); void dfs(int here); int main() { int caseNum = 0; cin >> caseNum; for (int i = 0; i > wordCnt; cin.ignore(); for (int j = 0; j < wordCnt; j++) { string word; std::getline(std::cin, word)..
EDITOR WARS #include #include #include #include using namespace std; struct NaiveDisjointSet { vector parent; NaiveDisjointSet(int n) : parent(n) { for (int i = 0; i < n; i++) parent[i] = i; } int find(int u) const { if (u == parent[u]) return u; return find(parent[u]); } void merge(int u, int v) { u = find(u); v = find(v); if (u == v) return; parent[u] = v; } }; struct OptimizedDisjointSet { vector parent,..