알고리즘(11)
-
백준 14891번 톱니바퀴 파이썬 시간(32ms) 1등 코드 공유
아무래도 연산을 최소화시켰더니 결과가 이렇게 된 것 같다!!재귀를 활용하되, 톱니바퀴가 동시에 돌아간다는 것을 이용해서 바깥쪽부터 바꿔주는 식으로 코드를 구성했음..# 14891. 톱니바퀴import sysinput = sys.stdin.readlinedef rotate(total: list, north: list, index: int, direction: int, arrow: int): # 왼쪽으로 전파 if arrow = 1: now_thing_west = total[index][(north[index]-2)%8] left_thing_east = total[index-1][(north[index-1]+2)%8] if now_thin..
2024.09.21 -
[acmicpc] 10814 나이순 정렬 정답 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 12..
2020.04.13 -
[acmicpc] 11650 좌표 정렬하기 정답 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 #include #include typedef struct _Point { int ..
2020.04.12 -
[C언어] 병합정렬 (Merge Sort) 소스 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 #include #include #define SIZE 10 void merge(int arr[], int start1, int end1, int start2, int end2) { // 앞 배열의 인덱스와 뒤 배열의 인덱스 int i = start1, j = start2; // 임시 배열 (정렬을 위한..
2020.04.12 -
[C언어] 퀵정렬 (Quick Sort) 소스 코드
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556#include #define SIZE 10 // 양쪽 값 변경 inline void swap(int *a, int *b){ int temp = *a; *a = *b; *b = temp;} // 퀵소트 함수 void quickSort(int arr[], int start, int end){ // 종료 조건 if(start >= end) return; // 피벗 (왼쪽 고정) int nPivot = arr[start]; int i = start, j = end; while(i
2020.04.12 -
[acmicpc] 백준 1018 체스판 다시 칠하기 정답 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 #include #include #define MIN(a,b) ((a > b) ? b : a) char g_arrBoard[52][52]; unsigned int fnGetMinFill(unsigned int nX, unsigned int nY) { unsigned int nMinCount = INT_MAX; unsigned int nTes..
2020.04.12