본문 바로가기

Algorithm

(49)
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..
CLOCKSYNC #include #include using namespace std; const int MAX_BUFFER_SIZE = 1024; const int SWITCH_NUM = 10; const int CLOCK_NUM = 16; const char* switches[10] = { {"oooxxxxxxxxxxxxx"}, {"xxxoxxxoxoxoxxxx"}, {"xxxxoxxxxxoxxxoo"}, {"oxxxooooxxxxxxxx"}, {"xxxxxxoooxoxoxxx"}, {"oxoxxxxxxxxxxxoo"}, {"xxxoxxxxxxxxxxoo"}, {"xxxxooxoxxxxxxoo"}, {"xoooooxxxxxxxxxx"}, {"xxxoooxxxoxxxoxx"} }; vector clockState; in..
TSP(Traveling Salesman Problem) #include #include #include using namespace std; const int MAX_BUFFER_SIZE = 1024; const int MAX_TOWN_NUM = 8; vector dist; bool visited[MAX_TOWN_NUM]; int townNum = 0; double getMinDistance(int curTown); void splitStringWithDelim(char* source, vector &result, char delim, int maxSize); int main() { int caseNum = 0; char buffer[MAX_BUFFER_SIZE] = {0, }; cin >> caseNum; for (int cIter = 0; cIter < ..
BOARDCOVER #include #include using namespace std; const int MAX_WIDTH = 20; const int coverType[4][3][2] = { {{0, 0}, {1, 0}, {1, -1}}, {{0, 0}, {0, 1}, {1, 1}}, {{0, 0}, {1, 0}, {1, 1}}, {{0, 0}, {1, 0}, {0, 1}} }; int boardHeight = 0, boardWidth = 0; int cover(vector &board); bool set(vector &board, int y, int x, int type, int flip); int main() { int caseNum = 0; string inputBuffer; char widthBuffer[MAX_..
PICNIC #include #include using namespace std; const int MAX_BUFFER_SIZE = 1024; int studentCnt = 0, pairCnt = 0; bool areFriend[10][10] = { false, }; int makePairing(bool done[10]); void splitStringWithDelim(char* source, vector &result, char delim, int maxSize); int main() { int caseNum = 0; char areFriendInput[MAX_BUFFER_SIZE]; vector areFriendInputParsed; bool done[10] = { false, }; cin >> caseNum; ..