본문 바로가기

Algorithm/Divide and Conquer

(6)
FANMEETING #include using namespace std; int getHugCnt(int start, int end); int getCenterHugCnt(int start, int end, int headPersonStart, int headPersonEnd); bool IsAllHugged(int headPersonIdx); const int MAX_PEOPLE_SIZE = 200001; char inputBuffer[MAX_PEOPLE_SIZE]; char member[MAX_PEOPLE_SIZE]; char fan[MAX_PEOPLE_SIZE]; int main() { int caseNum = 0; cin >> caseNum; cin.ignore(); for (int cIter = 0; cIter <..
FENCE 구현 소스 #include #include #include #include using namespace std; const int MAX_BUFFER_SIZE = 1024; vector fenceHeights; int getMaxArea(int start, int end); int getCenterMax(int start, int end, int mid); void splitStringWithDelim(char* source, vector &result, char delim, int maxSize); int main() { int caseNum = 0, elNum = 0; char inputBuffer[MAX_BUFFER_SIZE]; cin >> caseNum; for (int cIter = 0; cIt..
QUADTREE #include #include #include using namespace std; const int MAX_BUFFER_SIZE = 1024; string flip(const char *input, int idx); int main() { int caseNum = 0; char inputBuffer[MAX_BUFFER_SIZE]; cin >> caseNum; cin.ignore(); for (int cIter = 0; cIter < caseNum; cIter++) { cin.getline(inputBuffer, MAX_BUFFER_SIZE); string result = flip(inputBuffer, 0); cout
KARATSUBA #include #include #include #include using namespace std; const int MAX_NUMBER_SIZE = 1024; vector karatsuba(vector &a, vector &b); void exponential(vector &a, int k); void addTo(vector &a, vector &b); void subFrom(vector &a, vector &b); vector multiply(const vector &a, const vector &b); void normalize(vector &c); int getLength(char *arr); int main() { int caseNum = 0; char firstInput[MAX_NUMBER_..
QUICKSORT #include #include using namespace std; const int MAX_BUFFER_SIZE = 1024; void quick(vector &items, int start, int end); void splitStringWithDelim(char* source, vector &result, char delim, int maxSize); int main() { int caseNum = 0, elemNum = 0; char inputBuffer[MAX_BUFFER_SIZE]; vector items; cin >> caseNum; for (int cIter = 0; cIter > elemNum; cin.ignore(); items.clea..
MERGESORT #include #include using namespace std; const int MAX_BUFFER_SIZE = 1024; vector items; vector sort(int start, int end); vector merge(vector &first, vector &second); void splitStringWithDelim(char* source, vector &result, char delim, int maxSize); int main() { int caseNum = 0, itemNum = 0; char inputBuffer[MAX_BUFFER_SIZE]; cin >> caseNum; for (int cIter = 0; cIter > it..