├── .gitignore ├── 01003.py ├── 02533.py ├── 11053.py ├── 11722.py ├── 11726.py ├── 11727.py ├── 14267.py ├── 1y29h ├── week-6 │ ├── p02910.java │ └── p17255.java └── week-7 │ ├── p01149.java │ ├── p02294.java │ ├── p02579.java │ ├── p11722.java │ ├── p11727.java │ └── p15988.java ├── 22579.py ├── 25690.py ├── AnotherDoggedContender └── week-1 │ ├── BruteForce │ ├── 001.py │ ├── 002.py │ └── 003.py │ ├── Sort │ └── 001.py │ └── test.py ├── ClientSeungHyun └── week-02 │ ├── Divide_Conquer │ └── B11582.cpp │ ├── Eratosthenes │ ├── B1747.cpp │ └── B2960.cpp │ ├── Greedy │ ├── B11047.cpp │ ├── B1931.cpp │ ├── B19564.cpp │ └── B2217.cpp │ └── Recursive Call │ └── B17478.cpp ├── LICENSE ├── Lee-YouJ └── week-6 │ ├── 01620.py │ ├── 02580.pypy3 │ ├── 09375.py │ ├── 09663.pypy3 │ ├── 15663.py │ └── 27440.py ├── README.md ├── UnpackJungHo └── week-1 │ ├── 02309.cpp │ └── 11004.cpp ├── YangWooSong ├── week-02 │ ├── 10814.cpp │ ├── 10989.cpp │ ├── 11047.cpp │ ├── 11582.cpp │ ├── 11650.cpp │ ├── 11651.cpp │ ├── 1676.cpp │ ├── 1747.cpp │ ├── 17478.cpp │ ├── 1929.cpp │ ├── 1931.cpp │ ├── 19564.cpp │ ├── 2139.cpp │ ├── 2217.cpp │ ├── 2231.cpp │ ├── 2292.cpp │ ├── 26265.cpp │ ├── 2775.cpp │ ├── 28702.cpp │ ├── 2960.cpp │ ├── 30802.cpp │ ├── 31067.cpp │ └── 4153.cpp ├── week-03 │ ├── 1010.cpp │ ├── 10816.cpp │ ├── 10972.cpp │ ├── 15649.cpp │ ├── 15650.cpp │ ├── 1654.cpp │ ├── 1920.cpp │ ├── 2436.cpp │ ├── 2609.cpp │ ├── 31803.cpp │ └── 9613.cpp ├── week-04 │ ├── 10799.cpp │ ├── 11286.cpp │ ├── 1158.cpp │ ├── 1463.cpp │ ├── 1927.cpp │ ├── 1935.cpp │ ├── 2346.cpp │ └── 2800.cpp └── week-1 │ ├── 01476.cpp │ ├── 1018.cpp │ ├── 11004.cpp │ ├── 11651.cpp │ ├── 18870.cpp │ ├── 2309.cpp │ └── 2751.cpp ├── asj777 ├── week-01 │ ├── 1018.py │ ├── 11004.cpp │ ├── 11004.py │ ├── 11651.cpp │ ├── 11651.py │ ├── 1476.py │ ├── 18770.py │ ├── 1978.py │ └── 2309.py ├── week-02 │ ├── 10814.py │ ├── 10989.py │ ├── 11650.py │ ├── 1676.py │ ├── 17478.py │ ├── 1929.py │ ├── 1931.py │ ├── 2139.cpp │ ├── 2231.py │ ├── 26265.cpp │ ├── 2775.py │ ├── 28702.py │ ├── 31067.cpp │ ├── 4153.py │ └── 4421.py ├── week-03 │ ├── 10816.py │ ├── 1920.py │ └── 2609.py ├── week-04 │ ├── 10773.cpp │ ├── 10799.cpp │ ├── 1158.cpp │ ├── 1463.cpp │ ├── 1927.cpp │ ├── 1935.cpp │ ├── 4839.cpp │ └── 9935.cpp ├── week-06 │ ├── 17255.cpp │ ├── 2015.cpp │ ├── 21939.cpp │ └── 2910.cpp ├── week-07 │ ├── 1149.cpp │ ├── 11722.cpp │ ├── 11727.cpp │ ├── 15988.cpp │ ├── 2294.cpp │ └── 2579.cpp └── week-08 │ ├── 1354.cpp │ ├── 16400.cpp │ ├── 2565.cpp │ └── 5557.cpp ├── baektom └── week-1 │ └── testmd ├── danmoo6837 ├── week-1 │ ├── 2751 │ ├── 01018 │ └── 02309 └── week2 │ ├── 01931.c │ ├── 02960.c │ ├── 11047.c │ ├── 11582.c │ ├── 1747.c │ ├── 17478.c │ ├── 19564.c │ └── 2217.c ├── kadoling └── week-01 │ └── 2139.py ├── kws0315 ├── 2주차.txt ├── week-1 │ ├── BaekJoon-1018.py │ └── BaekJoon-2309.py ├── week-2 │ ├── BaeckJoon-11047.py │ ├── BaeckJoon-17478.py │ ├── BaeckJoon-19564.py │ ├── BaeckJoon-2217.py │ └── BaekJoon-2960.py └── week-3 │ ├── BaekJoon-10816.py │ ├── BaekJoon-1654.py │ ├── BaekJoon-1920.py │ ├── BaekJoon-2609.py │ └── BaekJoon-9613.py ├── mhe1239 ├── week-6 │ └── 2910.py ├── week-7 │ ├── 11727.py │ └── 15988.py └── week-8 │ ├── 2565.py │ └── 9461.py └── week06 /.gitignore: -------------------------------------------------------------------------------- 1 | \.idea\ -------------------------------------------------------------------------------- /01003.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | if __name__ == '__main__': 6 | dp = [[0] * 2 for _ in range(41)] 7 | dp[0][0] = 1 8 | dp[1][1] = 1 9 | 10 | for i in range(2, 41): 11 | dp[i][0] = dp[i - 1][0] + dp[i - 2][0] 12 | dp[i][1] = dp[i - 1][1] + dp[i - 2][1] 13 | 14 | for _ in range(int(input())): 15 | N = int(input()) 16 | print(dp[N][0], dp[N][1]) 17 | -------------------------------------------------------------------------------- /02533.py: -------------------------------------------------------------------------------- 1 | from sys import stdin, setrecursionlimit 2 | setrecursionlimit(int(1e6)) 3 | 4 | input = stdin.readline 5 | 6 | EARLY = 0 7 | GENERAL = 1 8 | 9 | def dfs(i): 10 | visited[i] = True 11 | dp[EARLY][i] = 1 12 | 13 | for v in graph[i]: 14 | if not visited[v]: 15 | dfs(v) 16 | dp[EARLY][i] += min(dp[EARLY][v], dp[GENERAL][v]) 17 | dp[GENERAL][i] += dp[EARLY][v] 18 | 19 | if __name__ == '__main__': 20 | N = int(input()) 21 | 22 | graph = [[] for _ in range(N + 1)] 23 | for _ in range(N - 1): 24 | u, v = map(int, input().split()) 25 | graph[u].append(v) 26 | graph[v].append(u) 27 | 28 | dp = [[0] * (N + 1) for _ in range(2)] 29 | visited = [False] * (N + 1) 30 | dfs(1) 31 | print(min(dp[EARLY][1], dp[GENERAL][1])) 32 | -------------------------------------------------------------------------------- /11053.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | def LIS(): 6 | for i in range(N): 7 | for j in range(i): 8 | if A[j] < A[i]: 9 | dp[i] = max(dp[i], dp[j] + 1) 10 | 11 | print(max(dp)) 12 | 13 | if __name__ == '__main__': 14 | N = int(input()) 15 | A = [*map(int, input().split())] 16 | 17 | dp = [1] * (N + 1) 18 | LIS() 19 | -------------------------------------------------------------------------------- /11722.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | if __name__ == '__main__': 6 | N = int(input()) 7 | A = [*map(int, input().split())] 8 | dp = [1] * N 9 | 10 | for i in range(1, N): 11 | for j in range(i): 12 | if A[j] > A[i]: 13 | dp[i] = max(dp[i], dp[j] + 1) 14 | print(max(dp)) 15 | -------------------------------------------------------------------------------- /11726.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | if __name__ == '__main__': 6 | N = int(input()) 7 | 8 | if N <= 2: 9 | print(N) 10 | else: 11 | dp = [0] * (N + 1) 12 | dp[1] = 1 13 | dp[2] = 2 14 | 15 | for i in range(3, N + 1): 16 | dp[i] = (dp[i - 1] + dp[i - 2]) % 10007 17 | 18 | print(dp[N]) 19 | -------------------------------------------------------------------------------- /11727.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | if __name__ == '__main__': 6 | N = int(input()) 7 | 8 | if N <= 2: 9 | print([0, 1, 3][N]) 10 | else: 11 | dp = [0] * (N + 1) 12 | dp[1] = 1 13 | dp[2] = 3 14 | 15 | for i in range(3, N + 1): 16 | dp[i] = (dp[i - 1] + 2 * dp[i - 2]) % 10007 17 | 18 | print(dp[N]) 19 | -------------------------------------------------------------------------------- /14267.py: -------------------------------------------------------------------------------- 1 | from sys import stdin, setrecursionlimit 2 | setrecursionlimit(int(1e5 + 4)) 3 | 4 | input = stdin.readline 5 | 6 | def dfs(i): 7 | for child in graph[i]: 8 | dp[child] += dp[i] 9 | dfs(child) 10 | 11 | if __name__ == '__main__': 12 | N, M = map(int, input().split()) 13 | A = [0] + list(map(int, input().split())) 14 | 15 | dp = [0] * (N + 1) 16 | for _ in range(M): 17 | i, w = map(int, input().split()) 18 | dp[i] += w 19 | 20 | graph = [[] for _ in range(N + 1)] 21 | for i in range(2, N + 1): 22 | graph[A[i]].append(i) 23 | dfs(1) 24 | 25 | del dp[0] 26 | print(*dp) 27 | -------------------------------------------------------------------------------- /1y29h/week-6/p02910.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class p02910 { 5 | 6 | public static void main(String[] args) throws IOException { 7 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | StringTokenizer st = new StringTokenizer(br.readLine()); 9 | int N = Integer.parseInt(st.nextToken()); 10 | 11 | Map nums = new LinkedHashMap<>(); 12 | 13 | st = new StringTokenizer(br.readLine()); 14 | for (int i = 0; i < N; i++) { 15 | int num = Integer.parseInt(st.nextToken()); 16 | nums.put(num, nums.getOrDefault(num, 0) + 1); 17 | } 18 | 19 | List> list = new ArrayList<>(nums.entrySet()); 20 | list.sort((e1, e2) -> e2.getValue().compareTo(e1.getValue())); 21 | 22 | StringBuilder sb = new StringBuilder(); 23 | for (Map.Entry entry : list) { 24 | int num = entry.getKey(); 25 | int cnt = entry.getValue(); 26 | for (int k=0; k ways = new HashSet<>(); 9 | 10 | public static void main(String[] args) throws IOException { 11 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 12 | 13 | String str = br.readLine(); 14 | length = str.length(); 15 | N = str.toCharArray(); 16 | 17 | for (int i = 0; i < length; i++) { 18 | dfs(i, i, String.valueOf(N[i]), String.valueOf(N[i])); 19 | } 20 | 21 | System.out.println(ways.size()); 22 | 23 | } 24 | 25 | public static void dfs(int left, int right, String str, String num) { 26 | 27 | // 완성 28 | if (left == 0 && right == length-1) { 29 | ways.add(String.valueOf(str)); 30 | return; 31 | } 32 | 33 | // 왼쪽 추가 34 | if (left > 0) { 35 | String nextNum = N[left-1] + num; 36 | String way = str + " " + nextNum; 37 | dfs(left-1, right, way, nextNum); 38 | } 39 | 40 | // 오른쪽 추가 41 | if (right < length-1) { 42 | String nextNum = num + N[right+1]; 43 | String way = str + " " + nextNum; 44 | dfs(left, right+1, way, nextNum); 45 | } 46 | 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /1y29h/week-7/p01149.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class p01149 { 5 | public static void main(String[] args) throws IOException { 6 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 7 | StringTokenizer st; 8 | 9 | int N = Integer.parseInt(br.readLine()); 10 | int [][] prices = new int[N+1][4]; 11 | int [][] res = new int[N+1][4]; 12 | 13 | for (int i=1; i<=N; i++) { 14 | st = new StringTokenizer(br.readLine()); 15 | for (int k=1; k<4; k++) { 16 | prices[i][k] = Integer.parseInt(st.nextToken()); 17 | } 18 | } 19 | 20 | res[1][1] = prices[1][1]; 21 | res[1][2] = prices[1][2]; 22 | res[1][3] = prices[1][3]; 23 | 24 | for (int i=2; i<=N; i++) { 25 | res[i][1] = Math.min(res[i-1][2]+prices[i][1], res[i-1][3]+prices[i][1]); 26 | res[i][2] = Math.min(res[i-1][1]+prices[i][2], res[i-1][3]+prices[i][2]); 27 | res[i][3] = Math.min(res[i-1][1]+prices[i][3], res[i-1][2]+prices[i][3]); 28 | } 29 | 30 | System.out.println( Math.min ( Math.min(res[N][1], res[N][2]), res[N][3]) ); 31 | 32 | } 33 | } -------------------------------------------------------------------------------- /1y29h/week-7/p02294.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class p02294 { 5 | public static void main(String[] args) throws IOException { 6 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 7 | StringTokenizer st = new StringTokenizer(br.readLine()); 8 | 9 | int n = Integer.parseInt(st.nextToken()); 10 | int k = Integer.parseInt(st.nextToken()); 11 | int [] prices = new int[n]; 12 | for (int i = 0; i < n; i++) { 13 | prices[i] = Integer.parseInt(br.readLine()); 14 | } 15 | Arrays.sort(prices); 16 | 17 | int [] res = new int[k+1]; 18 | for (int i=prices[0]; i<=k; i++) { 19 | 20 | int min = -1; 21 | 22 | // 나누어 떨어질 경우 23 | for (int j=0; j=prices[0]; j--) { 32 | if (res[j] > 0) { 33 | int remainder = i - j; 34 | if (res[remainder] > 0) { 35 | if (min != -1) min = Math.min(res[j] + res[remainder], min); 36 | else min = res[j] + res[remainder]; 37 | } 38 | } 39 | } 40 | 41 | res[i] = min; 42 | 43 | } 44 | 45 | System.out.println(res[k]); 46 | 47 | } 48 | } -------------------------------------------------------------------------------- /1y29h/week-7/p02579.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class p02579 { 4 | public static void main(String[] args) throws IOException { 5 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 6 | int stairsNum = Integer.parseInt(br.readLine()); 7 | 8 | if (stairsNum == 1) { 9 | System.out.println(br.readLine()); 10 | return; 11 | } 12 | 13 | int [] stairs = new int[stairsNum+1]; 14 | int [] max = new int[stairsNum+1]; 15 | 16 | stairs[0] = 0; 17 | for (int i = 1; i <= stairsNum; i++) { 18 | stairs[i] = Integer.parseInt(br.readLine()); 19 | } 20 | 21 | max[1] = stairs[1]; 22 | max[2] = stairs[1] + stairs[2]; 23 | 24 | for (int i=3; i<=stairsNum; i++) { 25 | 26 | int num1 = max[i-2] + stairs[i]; 27 | int num2 = max[i-3] + stairs[i-1] + stairs[i]; 28 | 29 | if (num1 > num2) max[i] = num1; 30 | else max[i] = num2; 31 | 32 | } 33 | 34 | System.out.println(max[stairsNum]); 35 | 36 | } 37 | } -------------------------------------------------------------------------------- /1y29h/week-7/p11722.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class p11722 { 5 | 6 | public static void main(String[] args) throws IOException { 7 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | 9 | int N = Integer.parseInt(br.readLine()); 10 | if (N==1) { 11 | System.out.println(1); 12 | return; 13 | } 14 | 15 | StringTokenizer st = new StringTokenizer(br.readLine()); 16 | int [] A = new int[N+1]; 17 | int [] length = new int[N+1]; 18 | for (int i = 1; i <= N; i++) { 19 | A[i] = Integer.parseInt(st.nextToken()); 20 | length[i] = 1; 21 | } 22 | 23 | int max = 1; 24 | for (int i = 2; i <= N; i++) { 25 | for (int k = 1; k < i; k++) { 26 | if (A[i] < A[k]) { 27 | if (length[k] + 1 > length[i]) 28 | length[i] = length[k] + 1; 29 | } 30 | } 31 | if (length[i] > max) max = length[i]; 32 | } 33 | 34 | System.out.println(max); 35 | 36 | } 37 | } -------------------------------------------------------------------------------- /1y29h/week-7/p11727.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class p11727 { 4 | 5 | public static void main(String[] args) throws IOException { 6 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 7 | int n = Integer.parseInt(br.readLine()); 8 | 9 | // n = 1일 때 10 | if (n==1) { 11 | System.out.println(1); 12 | return; 13 | } 14 | 15 | // n > 1일 때 16 | int [] res = new int[n]; 17 | res[0] = 1; 18 | res[1] = 3; 19 | 20 | for (int i=2; i=2) res[2] = 2; 21 | if (bigNums[T]>=3) res[3] = 4; 22 | for (int i=4; i<=bigNums[T]; i++) { 23 | res[i] = (int)(((long)res[i-1] + res[i-2] + res[i-3])%1000000009); 24 | } 25 | 26 | for (int i=1; i<=T; i++) { 27 | sb.append(res[nums[i]] + "\n"); 28 | } 29 | 30 | System.out.println(sb); 31 | 32 | } 33 | } -------------------------------------------------------------------------------- /22579.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | if __name__ == '__main__': 6 | N = int(input()) 7 | stair = [int(input()) for _ in range(N)] 8 | dp = [0] * N 9 | 10 | if N == 1: 11 | print(stair[0]) 12 | elif N == 2: 13 | print(stair[0] + stair[1]) 14 | else: 15 | dp[0] = stair[0] 16 | dp[1] = stair[0] + stair[1] 17 | dp[2] = max(stair[0] + stair[2], stair[1] + stair[2]) 18 | for i in range(3, N): 19 | dp[i] = max(dp[i-2] + stair[i], dp[i-3] + stair[i-1] + stair[i]) 20 | print(dp[N-1]) 21 | -------------------------------------------------------------------------------- /25690.py: -------------------------------------------------------------------------------- 1 | from sys import stdin, setrecursionlimit 2 | setrecursionlimit(10**6) 3 | 4 | input = stdin.readline 5 | 6 | WHITE = 0 7 | BLACK = 1 8 | 9 | def dfs(cur, parent): 10 | dp[WHITE][cur] = price[cur][WHITE] 11 | dp[BLACK][cur] = price[cur][BLACK] 12 | 13 | for child in graph[cur]: 14 | if child == parent: 15 | continue 16 | dfs(child, cur) 17 | 18 | dp[WHITE][cur] += min(dp[WHITE][child], dp[BLACK][child]) 19 | dp[BLACK][cur] += dp[WHITE][child] # 자식은 반드시 WHITE 20 | 21 | if __name__ == '__main__': 22 | N = int(input()) 23 | 24 | graph = [[] for _ in range(N)] 25 | for _ in range(N - 1): 26 | u, v = map(int, input().split()) 27 | graph[u].append(v) 28 | graph[v].append(u) 29 | 30 | price = [] 31 | for _ in range(N): 32 | w, b = map(int, input().split()) 33 | price.append([w, b]) 34 | 35 | dp = [[0] * N for _ in range(2)] # dp[WHITE][i], dp[BLACK][i] 36 | 37 | dfs(0, -1) 38 | print(min(dp[WHITE][0], dp[BLACK][0])) 39 | -------------------------------------------------------------------------------- /AnotherDoggedContender/week-1/BruteForce/001.py: -------------------------------------------------------------------------------- 1 | # 1. 숫자 9개를 입력받아 배열에 저장한다. 2 | # 2. 숫자 9개의 합을 구한 다음, 변수에 저장한다. (dataSum) 3 | # 3. 완료 플래그를 만든다. (flag, 답을 찾으면 True, 기본값은 False) 4 | # 4. for문 돌린다(i: 0~8, i++) 5 | # for문 돌린다(j: (i+1)~8, j++) 6 | # 배열에서 i번째 수와 j번째 수를 더한다.(chosenSum) 7 | # dataSum - chosenSum == 100이면 8 | # answer 배열에 i번째 수와 j번째 수를 제외하고 저장한다. 9 | # flag를 True로 바꾸고 break 한다. 10 | # flag가 true이면 break한다. 11 | # 5. answer 배열을 출력한다. 12 | 13 | import sys 14 | input = sys.stdin.readline 15 | 16 | data = [int(input().rstrip()) for _ in range(9) ] 17 | 18 | 19 | # data = [int(open(0).readline()) for _ in range(9) ] open(0)로 데이터를 받으면 런타임 에러가 나던데 왜 그런걸까요? 20 | dataSum = sum(data) 21 | answer=[] 22 | flag = False 23 | for i in range(0, len(data)): 24 | for j in range(i+1, len(data)): 25 | chosenSum = data[i] + data[j] 26 | if dataSum - chosenSum == 100: 27 | for x in range(0, len(data)): 28 | if x!= i and x != j: 29 | answer.append(data[x]) 30 | flag = True 31 | if flag == True: 32 | break 33 | answer.sort() 34 | 35 | print(*answer, sep='\n', end='') 36 | -------------------------------------------------------------------------------- /AnotherDoggedContender/week-1/BruteForce/002.py: -------------------------------------------------------------------------------- 1 | # (1 ≤ E ≤ 15, 1 ≤ S ≤ 28, 1 ≤ M ≤ 19) 2 | # 입력: E, S, M 값 3 | # 출력: 입력으로 받은 ESM 조합이 나오는 가장 빠른 연도 4 | # yearCount: 반복할 때 마다 1씩 추가. 5 | # 계속 E, S, M 값을 1씩 올리다가 E, S, M 값이 입력받은 ESM과 모두 일치하면 그 시점의 yearCount 출력 6 | # 각 값이 최대값에 도달하면 1로 초기화 7 | from sys import stdin 8 | input = stdin.readline 9 | inputE, inputS, inputM = map(int, input().split()) 10 | yearCount = 1 11 | changeE= changeS=changeM = 1 12 | while not(inputE == changeE and inputS == changeS and inputM == changeM): 13 | yearCount += 1 14 | if changeE == 15: 15 | changeE = 1 16 | else: 17 | changeE += 1 18 | if changeS == 28: 19 | changeS = 1 20 | else: 21 | changeS += 1 22 | if changeM == 19: 23 | changeM = 1 24 | else: 25 | changeM += 1 26 | 27 | print(yearCount) 28 | 29 | 30 | -------------------------------------------------------------------------------- /AnotherDoggedContender/week-1/BruteForce/003.py: -------------------------------------------------------------------------------- 1 | # 탐색 앵커의 범위: 0~(row - 7), 0~(col - 7) 2 | # 8*8 범위를 정하는 기준점 3 | # 보드 범위: 앵커 좌표가 a, b라고 하면, a~a+8, b~b+8 4 | # bChangeStack: 시작점이 B라고 칠 때 다시 칠해야 하는 정사각형의 개수 5 | # wChangeStack: 시작점이 W라고 칠 때 다시 칠해야 하는 정사각형의 개수 6 | # 매 탐색 마다...(현재 커서 좌표: cursorX, cursorY) 7 | # 시작점이 W라고 치면 8 | # 수직거리가 홀수면 B, 짝수면 W 9 | # (앵커와 커서의 수직거리가 홀수인데 문자가 W이거나)(앵커와 커서의 수직거리가 짝수인데 문자가 B이면) wChangeStack + 1 10 | # 시작점이 B라고 치면 11 | # 수직거리가 홀수면 W, 짝수면 B 12 | # (앵커와 커서의 수직거리가 홀수인데 문자가 B이거나)(앵커와 커서의 수직거리가 짝수인데 문자가 W이면) bChangeStack + 1 13 | # changeStack의 최솟값 출력 14 | from sys import stdin 15 | input = stdin.readline 16 | col, row = map(int, input().split()) 17 | boardArray = [] 18 | minChangeStack =40 19 | for i in range(col): 20 | boardArray.append(input().rstrip()) 21 | for anchorY in range(col - 7): 22 | for anchorX in range(row - 7): 23 | bChangeStack = 0 24 | wChangeStack = 0 25 | for cursorY in range(anchorY, anchorY + 8): 26 | for cursorX in range(anchorX, anchorX + 8): 27 | vDistance = (cursorX - anchorX)+(cursorY - anchorY) 28 | if (vDistance % 2 == 1 and boardArray[cursorY][cursorX] == 'W') or (vDistance % 2 == 0 and boardArray[cursorY][cursorX] == 'B'): 29 | wChangeStack += 1 30 | if (vDistance % 2 == 1 and boardArray[cursorY][cursorX] == 'B') or (vDistance % 2 == 0 and boardArray[cursorY][cursorX] == 'W'): 31 | bChangeStack += 1 32 | # 이 앵커에서 탐색 완료 33 | minChangeStack = min(minChangeStack, wChangeStack, bChangeStack) 34 | # 앵커 바꿈 35 | 36 | print(minChangeStack) 37 | -------------------------------------------------------------------------------- /AnotherDoggedContender/week-1/Sort/001.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | input = stdin.readline 3 | 4 | maxNum, kthNum = map(int, input().split()) 5 | numArr = [int(x) for x in input().split()] 6 | numArr.sort() 7 | print(numArr[kthNum - 1]) 8 | -------------------------------------------------------------------------------- /AnotherDoggedContender/week-1/test.py: -------------------------------------------------------------------------------- 1 | print("hello world") 2 | -------------------------------------------------------------------------------- /ClientSeungHyun/week-02/Divide_Conquer/B11582.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void Init() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | cout.tie(NULL); 12 | } 13 | 14 | int main() 15 | { 16 | Init(); 17 | 18 | int N{}; 19 | cin >> N; 20 | 21 | vector Grades; 22 | Grades.reserve(N); 23 | for (int i = 0; i < N; ++i) 24 | { 25 | int Grade{}; 26 | cin >> Grade; 27 | 28 | Grades.emplace_back(Grade); 29 | } 30 | 31 | int K{}; 32 | cin >> K; 33 | 34 | int Middle = N / 2; 35 | while (Middle > 0) 36 | { 37 | int JumpSize = N / Middle; 38 | for (int i = 0; i < N - 1; i = i + JumpSize) 39 | { 40 | sort(Grades.begin() + i, Grades.begin() + i + JumpSize); 41 | } 42 | 43 | if (Middle == K) 44 | { 45 | for (int i = 0; i < N; i++) 46 | { 47 | cout << Grades[i] << " "; 48 | } 49 | 50 | cout << '\n'; 51 | break; 52 | } 53 | 54 | Middle /= 2; 55 | } 56 | 57 | return 0; 58 | } -------------------------------------------------------------------------------- /ClientSeungHyun/week-02/Eratosthenes/B1747.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | using namespace std; 6 | 7 | void Init() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | cout.tie(NULL); 12 | } 13 | 14 | #define MAX_NUM 1003002 15 | bool Array[MAX_NUM] = { }; 16 | 17 | int main() 18 | { 19 | Init(); 20 | 21 | int N{}; 22 | cin >> N; 23 | 24 | Array[0] = Array[1] = true; 25 | for (int i = 2; i < MAX_NUM; ++i) 26 | { 27 | if (!Array[i]) 28 | { 29 | for (int j = 2; j * i < MAX_NUM; ++j) 30 | { 31 | Array[i * j] = true; 32 | } 33 | } 34 | } 35 | 36 | for (int i = N; i < MAX_NUM; ++i) 37 | { 38 | bool bResult = true; 39 | 40 | if (!Array[i]) 41 | { 42 | string str = to_string(i); 43 | 44 | for (int j = 0; j < str.length() / 2; ++j) 45 | { 46 | if (str[j] != str[str.length() - j - 1]) 47 | { 48 | bResult = false; 49 | } 50 | } 51 | 52 | if (bResult) 53 | { 54 | cout << i; 55 | break; 56 | } 57 | } 58 | } 59 | 60 | return 0; 61 | } -------------------------------------------------------------------------------- /ClientSeungHyun/week-02/Eratosthenes/B2960.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void Init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | int main() 14 | { 15 | Init(); 16 | 17 | int N{}, K{}; 18 | cin >> N >> K; 19 | 20 | int* Arr = new int[N + 1]; 21 | memset(Arr, 0, sizeof(int) * (N + 1)); 22 | 23 | int Cnt{ 0 }; 24 | for (int i = 2; i <= N; ++i) 25 | { 26 | for (int j = 1; j * i <= N; ++j) 27 | { 28 | if (!Arr[i * j]) 29 | { 30 | Arr[i * j] = true; 31 | ++Cnt; 32 | 33 | if (Cnt == K) 34 | { 35 | cout << j * i; 36 | } 37 | } 38 | } 39 | } 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /ClientSeungHyun/week-02/Greedy/B11047.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void Init() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | cout.tie(NULL); 12 | } 13 | 14 | int main() 15 | { 16 | Init(); 17 | 18 | int N{}, K{}; 19 | cin >> N >> K; 20 | 21 | vector Coins; 22 | Coins.reserve(N); 23 | for (int i = 0; i < N; ++i) 24 | { 25 | int Coin{}; 26 | cin >> Coin; 27 | 28 | Coins.emplace_back(Coin); 29 | } 30 | 31 | sort(Coins.begin(), Coins.end(), greater<>()); 32 | 33 | int Cnt{}; 34 | for (int i = 0; i < K || K > 0; ++i) 35 | { 36 | if (K / Coins[i] > 0) 37 | { 38 | Cnt += K / Coins[i]; 39 | K %= Coins[i]; 40 | } 41 | } 42 | 43 | 44 | //옹 이것도 되네 45 | //int Index{}, Cnt{}; 46 | //while (K) 47 | //{ 48 | // if (K / Coins[Index] > 0) 49 | // { 50 | // ++Cnt; 51 | // K -= Coins[Index]; 52 | // } 53 | // else 54 | // { 55 | // ++Index; 56 | // } 57 | //} 58 | 59 | cout << Cnt; 60 | 61 | return 0; 62 | } -------------------------------------------------------------------------------- /ClientSeungHyun/week-02/Greedy/B1931.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | // 실패 8 | 9 | void Init() 10 | { 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | cout.tie(NULL); 14 | } 15 | 16 | bool SortSecond(pair A, pair B) 17 | { 18 | if (A.second == B.second) 19 | return A.first < B.first; 20 | 21 | return A.second < B.second; 22 | } 23 | 24 | int main() 25 | { 26 | Init(); 27 | 28 | int N{}; 29 | cin >> N; 30 | 31 | vector> Times; 32 | Times.reserve(N); 33 | 34 | for (int i = 0; i < N; ++i) 35 | { 36 | int Start{}, End{}; 37 | cin >> Start >> End; 38 | 39 | Times.push_back({ Start, End }); 40 | } 41 | 42 | sort(Times.begin(), Times.end(), SortSecond); 43 | 44 | int Cnt{ 1 }; 45 | int Time = Times[0].second; 46 | for (int i = 1; i < N; ++i) 47 | { 48 | if (Time <= Times[i].first) 49 | { 50 | Time = Times[i].second; 51 | ++Cnt; 52 | } 53 | } 54 | 55 | cout << Cnt; 56 | 57 | return 0; 58 | } -------------------------------------------------------------------------------- /ClientSeungHyun/week-02/Greedy/B19564.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void Init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | int main() 14 | { 15 | Init(); 16 | 17 | string str; 18 | cin >> str; 19 | 20 | int cnt = 1; 21 | for (int i = 1; i < str.length(); ++i) 22 | { 23 | if (str[i] <= str[i - 1]) 24 | { 25 | ++cnt; 26 | } 27 | } 28 | 29 | cout << cnt; 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /ClientSeungHyun/week-02/Greedy/B2217.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void Init() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | cout.tie(NULL); 12 | } 13 | 14 | int main() 15 | { 16 | Init(); 17 | 18 | int N{}; 19 | cin >> N; 20 | 21 | vector Ropes; 22 | Ropes.reserve(N); 23 | 24 | for (int i = 0; i < N; ++i) 25 | { 26 | int Rope{}; 27 | cin >> Rope; 28 | 29 | Ropes.emplace_back(Rope); 30 | } 31 | 32 | sort(Ropes.begin(), Ropes.end(), greater<>()); 33 | 34 | int Max{}; 35 | for (int i = 0; i < N; ++i) 36 | { 37 | Max = std::max(Max, Ropes[i] * (i + 1)); 38 | } 39 | 40 | cout << Max; 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /ClientSeungHyun/week-02/Recursive Call/B17478.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | // 실패 7 | 8 | void Init() 9 | { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | cout.tie(NULL); 13 | } 14 | 15 | void PrintRe(int N, string str) 16 | { 17 | for (int i = 0; i < N - 1; ++i) 18 | { 19 | cout << "____"; 20 | } 21 | 22 | cout << str << "\n"; 23 | } 24 | 25 | void Func(int Depth, int N = 1) 26 | { 27 | PrintRe(N, "\"재귀함수가 뭔가요?\""); 28 | 29 | if (Depth >= N) 30 | { 31 | PrintRe(N, "\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어."); 32 | PrintRe(N, "마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지."); 33 | PrintRe(N, "그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\""); 34 | 35 | Func(Depth, N + 1); 36 | } 37 | else if (Depth < N) 38 | { 39 | PrintRe(N, "\"재귀함수는 자기 자신을 호출하는 함수라네\""); 40 | } 41 | 42 | PrintRe(N, "라고 답변하였지."); 43 | 44 | } 45 | 46 | int main() 47 | { 48 | Init(); 49 | 50 | int N{}; 51 | cin >> N; 52 | 53 | cout << "어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.\n"; 54 | Func(N); 55 | 56 | return 0; 57 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 youngrok kim 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Lee-YouJ/week-6/01620.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | if __name__ == '__main__': 6 | N, M = map(int, input().split()) 7 | 8 | no = 1 9 | pokemon_list = {} 10 | for _ in range(N): 11 | name = input().rstrip() 12 | pokemon_list[name] = no 13 | pokemon_list[str(no)] = name 14 | no += 1 15 | 16 | res = [] 17 | for _ in range(M): 18 | res.append(pokemon_list[input().rstrip()]) 19 | 20 | print(*res, sep='\n') 21 | -------------------------------------------------------------------------------- /Lee-YouJ/week-6/02580.pypy3: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | def bt(n): 6 | if n == 81: 7 | return True 8 | 9 | # 주어진 n 이용 -> 2차원 리스트에서의 좌표 구하기 10 | x, y = n // 9, n % 9 11 | 12 | if board[x][y] == 0: 13 | for val in range(1, 10): 14 | if isValid(x, y, val): 15 | board[x][y] = val 16 | if bt(n + 1): 17 | return True 18 | board[x][y] = 0 19 | return False 20 | else: 21 | return bt(n + 1) 22 | 23 | # 가로/세로 줄 혹은 자신이 속한 영역 3*3 영역에 자신과 같은 숫자가 있는 지 검사 24 | def isValid(x, y, val): 25 | for i in range(9): 26 | if board[x][i] == val or board[i][y] == val: 27 | return False 28 | lu_x, lu_y = (x // 3) * 3, (y // 3) * 3 29 | for i in range(lu_x, lu_x + 3): 30 | for j in range(lu_y, lu_y + 3): 31 | if board[i][j] == val: 32 | return False 33 | return True 34 | 35 | if __name__ == '__main__': 36 | board = [[*map(int, input().split())] for _ in range(9)] 37 | 38 | bt(0) 39 | 40 | for i in range(9): 41 | print(*board[i]) 42 | -------------------------------------------------------------------------------- /Lee-YouJ/week-6/09375.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | from sys import stdin 3 | 4 | input = stdin.readline 5 | 6 | if __name__ == '__main__': 7 | res = [] 8 | for _ in range(int(input())): 9 | n = int(input()) 10 | clothes = [input().split()[1] for _ in range(n)] 11 | 12 | cnt = 1 13 | for _, value in Counter(clothes).items(): 14 | cnt *= value + 1 15 | res.append(cnt - 1) 16 | 17 | print(*res, sep='\n') 18 | -------------------------------------------------------------------------------- /Lee-YouJ/week-6/09663.pypy3: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | def bt(row): 6 | global res 7 | if row == N: 8 | res += 1 9 | return 10 | 11 | for col in range(N): 12 | if not col_check[col] and not diag1_check[row + col] and not diag2_check[row - col + N - 1]: 13 | col_check[col] = diag1_check[row + col] = diag2_check[row - col + N - 1] = True 14 | bt(row + 1) 15 | col_check[col] = diag1_check[row + col] = diag2_check[row - col + N - 1] = False 16 | 17 | if __name__ == '__main__': 18 | N = int(input()) 19 | res = 0 20 | col_check = [False] * N 21 | diag1_check = [False] * (2*N-1) 22 | diag2_check = [False] * (2*N-1) 23 | bt(0) 24 | print(res) 25 | -------------------------------------------------------------------------------- /Lee-YouJ/week-6/15663.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | def bt(): 6 | if len(temp) == M: 7 | res.append(' '.join(map(str, temp))) 8 | return 9 | 10 | prev = None 11 | for i in range(N): 12 | if A[i] != prev and not visited[i]: 13 | prev = A[i] 14 | temp.append(A[i]) 15 | visited[i] = True 16 | bt() 17 | visited[i] = False 18 | temp.pop() 19 | 20 | if __name__ == '__main__': 21 | N, M = map(int, input().split()) 22 | A = [*map(int, input().split())] 23 | 24 | A.sort() 25 | visited = [False] * N 26 | res = [] 27 | temp = [] 28 | 29 | bt() 30 | 31 | print(*res, sep='\n') 32 | 33 | -------------------------------------------------------------------------------- /Lee-YouJ/week-6/27440.py: -------------------------------------------------------------------------------- 1 | from collections import deque, defaultdict 2 | from sys import stdin 3 | 4 | input = stdin.readline 5 | 6 | def bfs(X): 7 | if X == 1: 8 | return 0 9 | memo = defaultdict(int) 10 | queue = deque([X]) 11 | while queue: 12 | cur = queue.popleft() 13 | if cur == 1: 14 | return memo[cur] 15 | if cur % 3 == 0 and cur // 3 not in memo: 16 | memo[cur//3] = memo[cur] + 1 17 | queue.append(cur // 3) 18 | if cur % 2 == 0 and cur // 2 not in memo: 19 | memo[cur//2] = memo[cur] + 1 20 | queue.append(cur // 2) 21 | if cur - 1 not in memo: 22 | memo[cur - 1] = memo[cur] + 1 23 | queue.append(cur - 1) 24 | 25 | if __name__ == '__main__': 26 | X = int(input()) 27 | print(bfs(X)) 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 알고리즘 알고잇즘? 2 | 이 레포지토리는 코딩 테스트를 위한 알고리즘 수업 `알고리즘 알고잇즘?` 의 학습 자료와 학습자의 문제 풀이 코드를 관리하기 위해 만들어졌습니다. 3 | 4 | ## 목차 5 | - [목적](#목적) 6 | - [코드 제출 및 리뷰 가이드](#코드-제출-및-리뷰-가이드) 7 | - [브랜치 전략](#브랜치-전략) 8 | - [문의](#문의) 9 | 10 | ## 목적 11 | - 알고리즘 개념 학습 및 실습 문제 해결 12 | - 코드 리뷰를 통한 효율적인 피드백과 코드 품질 향상 13 | - 다양한 풀이법 공유 및 토론 14 | 15 | ## 코드 제출 및 리뷰 가이드 16 | 1. **연습문제 및 과제 확인:** 17 | `Notion`을 참고해 주차 별 연습문제 및 과제 확인 18 | 2. **저장소 fork** 19 | 본 저장소를 자신의 Github에 `fork`합니다. 20 | 21 | 3. **브랜치 생성:** 22 | 문제를 풀기 전, 자신의 `Github` ID와 해당 주차를 포함해 새로운 브랜치를 생성합니다. 23 | 예시: `rogi-rogi/week-1` 24 | 25 | 4. **코드 작성:** 26 | `/[자신의 Github ID]/[주차]/`폴더 내 문제 풀이 코드를 작성해주세요. 27 | 예시: `/rogi-rogi/week-01/01000.py` 28 | 29 | 5. **Pull Request(PR) 생성:** 30 | 본 레포지토리의 `main` 브랜치로 PR 보내세요. PR 제목은 `[주차], [자신의 Github ID]` 형식으로 작성합니다. 31 | 예시: `week-01, rogi-rogi` 32 | 33 | 6. **코드 리뷰:** 34 | 강사 및 동료 학생들이 PR을 통해 코드 리뷰를 진행합니다. 리뷰가 완료되면 `merge`합니다. 35 | 리뷰는 [이곳](https://github.com/rogi-rogi/algorithm-class/pulls?q=is%3Apr+is%3Aclosed)에서 본인 PR을 찾아 확인하실 수 있습니다. 36 | 37 | ## 브랜치 전략 38 | - **main 브랜치:** 39 | 리뷰 완료된 최종 코드가 포함됩니다. 40 | - **개인 브랜치:** 41 | 학습자가 제출한 코드 작업은 별도의 브랜치에서 진행합니다. 42 | 43 | ## 문의 44 | 질문이나 건의사항이 있다면 [이슈](https://github.com/rogi-rogi/algorithm-class/issues)를 등록하거나, 강사에게 직접 문의해주세요. 45 | 46 | --- 47 | 48 | 즐겁게 코딩하고, 서로의 코드를 통해 많은 것을 배워가길 바랍니다! -------------------------------------------------------------------------------- /UnpackJungHo/week-1/02309.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main1() { 7 | int sum = 0; 8 | vector v; 9 | for (int i = 0; i < 9; i++) { 10 | int num; 11 | cin >> num; 12 | v.push_back(num); 13 | sum += num; 14 | } 15 | 16 | sort(v.begin(), v.end()); 17 | 18 | for (int i = 0; i < v.size(); i++) { 19 | for (int j = i + 1; j < v.size(); j++) { 20 | if ((sum - v[i] - v[j]) == 100) { 21 | for (int k = 0; k < v.size(); k++) { 22 | if (k != i && k != j) { 23 | cout << v[k] << '\n'; 24 | } 25 | } 26 | return 0; 27 | } 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /UnpackJungHo/week-1/11004.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int x; 8 | cin >> x; 9 | vector v; 10 | for (int i = 0; i < x; i++) { 11 | int num; 12 | cin >> num; 13 | v.push_back(num); 14 | } 15 | 16 | sort(v.begin(), v.end()); 17 | 18 | for (int i = 0; i < x; i++) { 19 | cout << v[i] << '\n'; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /YangWooSong/week-02/10814.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | struct Person 7 | { 8 | int age = 0; 9 | int index = 0; 10 | string name; 11 | }; 12 | 13 | bool CompareAge(Person& a, Person& b) 14 | { 15 | if (a.age != b.age) 16 | return a.age < b.age; 17 | else if (a.age == b.age) 18 | return a.index < b.index; 19 | } 20 | 21 | int main() 22 | { 23 | int n = 0; 24 | vector person_list; 25 | cin >> n; 26 | 27 | for (int i = 0; i < n; ++i) 28 | { 29 | Person p; 30 | cin >> p.age >> p.name; 31 | p.index = i; 32 | person_list.push_back(p); 33 | } 34 | 35 | sort(person_list.begin(), person_list.end(), CompareAge); 36 | 37 | for (int i = 0; i < n; ++i) 38 | { 39 | cout << person_list[i].age << " " << person_list[i].name << endl; 40 | } 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/10989.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void Init() 7 | { 8 | ios::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | int main() 14 | { 15 | Init(); 16 | 17 | int iCountArr[10000] = {}; 18 | int iNum(0), tmp; 19 | 20 | cin >> iNum; 21 | 22 | for (int i = 0; i < iNum; ++i) 23 | { 24 | cin >> tmp; 25 | iCountArr[tmp - 1] += 1; 26 | } 27 | 28 | for (int i = 0; i < 10000;) 29 | { 30 | if (iCountArr[i] != 0) 31 | { 32 | cout << i + 1 << "\n"; 33 | iCountArr[i] -= 1; 34 | } 35 | else 36 | i++; 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /YangWooSong/week-02/11047.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void Init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | int main() 14 | { 15 | Init(); 16 | 17 | int N = 0; 18 | int K = 0; 19 | int TotalCount = 0; 20 | vector vCoinList; 21 | 22 | cin >> N >> K; 23 | 24 | for (int coin, i = 0; i < N; ++i) 25 | { 26 | cin >> coin; 27 | vCoinList.push_back(coin); 28 | } 29 | 30 | for (int i = vCoinList.size() - 1; i >= 0; --i) 31 | { 32 | if (vCoinList[i] <= K) 33 | { 34 | int Count = K / vCoinList[i]; 35 | TotalCount += Count; 36 | K -= Count * vCoinList[i]; 37 | } 38 | } 39 | 40 | cout << TotalCount; 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/11582.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogi-rogi/algorithm-class/7881e23c93e5a12f9998927128c4e3ba7468cf8c/YangWooSong/week-02/11582.cpp -------------------------------------------------------------------------------- /YangWooSong/week-02/11650.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void Init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | struct Inform 14 | { 15 | int first = 0; 16 | int second = 0; 17 | }; 18 | 19 | bool Compare(Inform& a, Inform& b) 20 | { 21 | if (a.first == b.first) 22 | { 23 | return a.second < b.second; 24 | } 25 | else 26 | return a.first < b.first; 27 | } 28 | 29 | int main() 30 | { 31 | Init(); 32 | 33 | vector inform_list; 34 | 35 | int count = 0; 36 | cin >> count; 37 | 38 | for (int i = 0; i < count; ++i) 39 | { 40 | Inform p; 41 | cin >> p.first >> p.second; 42 | inform_list.push_back(p); 43 | } 44 | 45 | sort(inform_list.begin(), inform_list.end(), Compare); 46 | 47 | for (int i = 0; i < count; ++i) 48 | { 49 | cout << inform_list[i].first << " " << inform_list[i].second << "\n"; 50 | } 51 | 52 | return 0; 53 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/11651.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void Init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | struct Inform 14 | { 15 | int first = 0; 16 | int second = 0; 17 | }; 18 | 19 | bool Compare(Inform& a, Inform& b) 20 | { 21 | if (a.second == b.second) 22 | { 23 | return a.first < b.first; 24 | } 25 | else 26 | return a.second < b.second; 27 | } 28 | 29 | int main() 30 | { 31 | Init(); 32 | 33 | vector vList; 34 | 35 | int count = 0; 36 | cin >> count; 37 | 38 | for (int i = 0; i < count; ++i) 39 | { 40 | Inform p; 41 | cin >> p.first >> p.second; 42 | vList.push_back(p); 43 | } 44 | 45 | sort(vList.begin(), vList.end(), Compare); 46 | 47 | for (int i = 0; i < count; ++i) 48 | { 49 | cout << vList[i].first << " " << vList[i].second << "\n"; 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /YangWooSong/week-02/1676.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void Init() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | } 10 | 11 | int main() 12 | { 13 | int n = 0; 14 | int count = 0; 15 | cin >> n; 16 | 17 | for (int i = 5; i <= n; i *= 5) 18 | { 19 | count += n / i; 20 | } 21 | 22 | cout << count; 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/1747.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogi-rogi/algorithm-class/7881e23c93e5a12f9998927128c4e3ba7468cf8c/YangWooSong/week-02/1747.cpp -------------------------------------------------------------------------------- /YangWooSong/week-02/17478.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogi-rogi/algorithm-class/7881e23c93e5a12f9998927128c4e3ba7468cf8c/YangWooSong/week-02/17478.cpp -------------------------------------------------------------------------------- /YangWooSong/week-02/1929.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogi-rogi/algorithm-class/7881e23c93e5a12f9998927128c4e3ba7468cf8c/YangWooSong/week-02/1929.cpp -------------------------------------------------------------------------------- /YangWooSong/week-02/1931.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void Init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | bool CompareEndTime(pair p1, pair p2) 14 | { 15 | if (p1.second == p2.second) 16 | return p1.first < p2.first; 17 | return p1.second < p2.second; 18 | } 19 | 20 | int main() 21 | { 22 | Init(); 23 | 24 | vector> vMeetingList; 25 | int c = 0; 26 | int count = 1; 27 | int endTime = 0; 28 | cin >> c; 29 | 30 | for (int n1,n2,i = 0; i < c; ++i) 31 | { 32 | cin >> n1 >> n2; 33 | vMeetingList.push_back({ n1,n2 }); 34 | } 35 | 36 | sort(vMeetingList.begin(), vMeetingList.end(), CompareEndTime); 37 | 38 | endTime = vMeetingList[0].second; 39 | for (int i = 1; i < vMeetingList.size(); ++i) 40 | { 41 | if(vMeetingList[i].first >= endTime) 42 | { 43 | ++count; 44 | endTime = vMeetingList[i].second; 45 | } 46 | } 47 | 48 | cout << count; 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/19564.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void Init() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | } 10 | 11 | int main() 12 | { 13 | Init(); 14 | 15 | string s; 16 | cin >> s; 17 | 18 | int k = 1; 19 | for (int i = 1; i < s.length(); ++i) 20 | { 21 | if ((int)s[i] <= (int)s[i - 1]) 22 | { 23 | k++; 24 | } 25 | } 26 | 27 | cout << k; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/2139.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void Init() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | } 10 | 11 | bool Calculate_LeapYear(const int year) 12 | { 13 | if (year % 4 == 0) 14 | { 15 | if (year % 100 == 0) 16 | { 17 | if (year % 400 == 0) 18 | { 19 | return true; 20 | } 21 | 22 | return false; 23 | } 24 | 25 | return true; 26 | } 27 | 28 | return false; 29 | } 30 | 31 | int main() 32 | { 33 | Init(); 34 | 35 | while (1) 36 | { 37 | int year = 0; 38 | int month = 0; 39 | int day = 0; 40 | int count = 0; 41 | bool is_leap_year = false; 42 | 43 | cin >> day >> month >> year; 44 | 45 | if (day == 0 && month == 0 && year == 0) 46 | break; 47 | 48 | is_leap_year = Calculate_LeapYear(year); 49 | 50 | for (int i = 1; i < month ; ++i) 51 | { 52 | if (i == 2) 53 | { 54 | if (is_leap_year) 55 | { 56 | count += 29; 57 | } 58 | else 59 | { 60 | count += 28; 61 | } 62 | } 63 | else if (i == 4 || i == 6 || i == 9 || i == 11) 64 | { 65 | count += 30; 66 | } 67 | else 68 | { 69 | count += 31; 70 | } 71 | } 72 | 73 | count += day; 74 | 75 | cout << count << "\n"; 76 | } 77 | 78 | 79 | return 0; 80 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/2217.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void Init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | int main() 14 | { 15 | Init(); 16 | 17 | int K = 0; 18 | cin >> K; 19 | 20 | vector vRopeWeight; 21 | 22 | for (int maxW, i = 0; i < K; ++i) 23 | { 24 | cin >> maxW; 25 | vRopeWeight.push_back(maxW); 26 | } 27 | 28 | sort(vRopeWeight.begin(), vRopeWeight.end(), greater()); 29 | 30 | int Result = 0; 31 | for (int i = 0; i < vRopeWeight.size(); ++i) 32 | { 33 | if (Result < (i + 1) * vRopeWeight[i]) 34 | Result = (i + 1) * vRopeWeight[i]; 35 | } 36 | 37 | cout << Result; 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/2231.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void Init() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | } 10 | 11 | int main() 12 | { 13 | Init(); 14 | 15 | int num = 0; 16 | 17 | cin >> num; 18 | 19 | for (int i = 1; i < num; ++i) 20 | { 21 | int sum = 0, tmp = i; 22 | 23 | while (tmp > 0) 24 | { 25 | sum += tmp % 10; 26 | tmp = tmp / 10; 27 | } 28 | sum += i; 29 | if (sum == num) 30 | { 31 | cout << i << "\n"; 32 | return 0; 33 | } 34 | } 35 | 36 | cout << 0 << "\n"; 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/2292.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void Init() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | } 10 | 11 | int main() 12 | { 13 | Init(); 14 | 15 | int n = 0; 16 | cin >> n; 17 | 18 | int count = 1; 19 | int total = 1; 20 | 21 | while (1) 22 | { 23 | if (n <= total) 24 | break; 25 | 26 | ++count; 27 | total += count * 6 - 6; 28 | } 29 | 30 | cout << count; 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/26265.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void Init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | bool Compare(pair set1, pair set2) 14 | { 15 | if (set1.first == set2.first) 16 | { 17 | return set1.second > set2.second; 18 | } 19 | else 20 | { 21 | return set1.first < set2.first; 22 | } 23 | } 24 | 25 | int main() 26 | { 27 | Init(); 28 | 29 | int n = 0; 30 | cin >> n; 31 | 32 | vector> v_List; 33 | for (int i = 0; i < n; ++i) 34 | { 35 | string mento, mentee; 36 | cin >> mento >> mentee; 37 | v_List.push_back(make_pair(mento, mentee)); 38 | } 39 | 40 | sort(v_List.begin(), v_List.end(), Compare); 41 | 42 | for (auto& iter : v_List) 43 | { 44 | cout << iter.first << " " << iter.second << "\n"; 45 | } 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/2775.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | void Init() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | } 11 | 12 | int GetNum(int k, int n) 13 | { 14 | if (n == 1) 15 | return 1; 16 | else if (k == 0) 17 | return n; 18 | return GetNum(k, n - 1) + GetNum(k - 1, n);; 19 | } 20 | 21 | int main() 22 | { 23 | Init(); 24 | 25 | int t = 0; 26 | cin >> t; 27 | 28 | for (int i = 0; i < t; ++i) 29 | { 30 | int k = 0; 31 | int n = 0; 32 | 33 | cin >> k; 34 | cin >> n; 35 | 36 | 37 | cout << GetNum(k, n) << "\n"; 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /YangWooSong/week-02/28702.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void Init() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | } 11 | 12 | int main() 13 | { 14 | Init(); 15 | 16 | string s1, s2, s3; 17 | 18 | cin >> s1; 19 | cin >> s2; 20 | cin >> s3; 21 | 22 | int Answer = 0; 23 | 24 | if (atoi(&s1[0]) != 0) 25 | Answer = stoi(s1) + 3; 26 | else if (atoi(&s2[0]) != 0) 27 | Answer = stoi(s2) + 2; 28 | else if (atoi(&s3[0]) != 0) 29 | Answer = stoi(s3) + 1; 30 | 31 | if (Answer % 3 == 0 && Answer % 5 == 0) 32 | cout << "FizzBuzz" << endl; 33 | else if (Answer % 3 == 0) 34 | cout << "Fizz" << endl; 35 | else if (Answer % 5 == 0) 36 | cout << "Buzz" << endl; 37 | else 38 | cout << to_string(Answer) << endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /YangWooSong/week-02/2960.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int sieve_of_eratosthenes(int n, int k) { 6 | vector is_prime(n + 1, true); 7 | is_prime[0] = is_prime[1] = false; 8 | 9 | int count = 0; 10 | 11 | for (int i = 2; i <= n; i++) 12 | { 13 | if (is_prime[i]) 14 | { 15 | count++; 16 | if (count == k) 17 | return i; 18 | 19 | for (int j = i * i; j <= n; j += i) 20 | { 21 | if (is_prime[j]) 22 | { 23 | count++; 24 | is_prime[j] = false; 25 | 26 | if (count == k) 27 | return j; 28 | } 29 | } 30 | } 31 | } 32 | return 0; 33 | } 34 | 35 | int main() { 36 | int n = 0, k = 0; 37 | cin >> n >> k; 38 | 39 | int answer = sieve_of_eratosthenes(n, k); 40 | 41 | cout << answer; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /YangWooSong/week-02/30802.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void Init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | int main() 14 | { 15 | Init(); 16 | 17 | int n = 0; 18 | int size[6] = {}; 19 | int t = 0; 20 | int p = 0; 21 | int total_shirt = 0; 22 | 23 | cin >> n; 24 | 25 | for (int i = 0; i < 6; ++i) 26 | { 27 | cin >> size[i]; 28 | } 29 | 30 | cin >> t >> p; 31 | 32 | for (int i = 0; i < 6; ++i) 33 | { 34 | if (size[i] % t== 0) 35 | total_shirt += size[i] / t; 36 | else 37 | total_shirt += size[i] / t + 1; 38 | } 39 | 40 | cout << total_shirt << "\n"; 41 | cout << n / p << " " << n % p; 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /YangWooSong/week-02/31067.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void Init() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | } 11 | 12 | int main() 13 | { 14 | Init(); 15 | 16 | int n = 0; 17 | int k = 0; 18 | int count = 0; 19 | 20 | vector v_track; 21 | 22 | cin >> n >> k; 23 | 24 | for (int num, i = 0; i < n; ++i) 25 | { 26 | cin >> num; 27 | v_track.push_back(num); 28 | } 29 | 30 | for (int i = 1; i < n; ++i) 31 | { 32 | if (v_track[i] <= v_track[i - 1]) 33 | { 34 | if (v_track[i] + k > v_track[i - 1]) 35 | { 36 | v_track[i] += k; 37 | ++count; 38 | } 39 | else 40 | { 41 | count = -1; 42 | break; 43 | } 44 | } 45 | } 46 | 47 | cout << count; 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /YangWooSong/week-02/4153.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void Init() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | } 10 | 11 | int main() 12 | { 13 | Init(); 14 | 15 | while (1) 16 | { 17 | int n[3] = { 0 }; 18 | cin >> n[0] >> n[1] >> n[2]; 19 | 20 | if (n[0] == 0 && n[1] == 0 && n[2] == 0) 21 | break; 22 | 23 | int biggest = 0; 24 | for (int i = 0; i < 3; ++i) 25 | { 26 | if (biggest < n[i]) 27 | biggest = n[i]; 28 | } 29 | 30 | int sum = 0; 31 | for (int i = 0; i < 3; ++i) 32 | { 33 | if (biggest != n[i]) 34 | sum += n[i] * n[i]; 35 | } 36 | 37 | if (sum == biggest * biggest) 38 | cout << "right" << "\n"; 39 | else 40 | cout << "wrong" << "\n"; 41 | } 42 | return 0; 43 | } -------------------------------------------------------------------------------- /YangWooSong/week-03/1010.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void Init() { 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | cout.tie(NULL); 8 | } 9 | 10 | long long CombinationCount(int n1, int n2) 11 | { 12 | int big = max(n1, n2); 13 | int small = min(n1, n2); 14 | 15 | long long result = 1; 16 | int tmp = 1; 17 | for (int i = big; i > big - small ; --i, tmp++) 18 | { 19 | result *= i; 20 | result /= tmp; 21 | } 22 | return result; 23 | } 24 | 25 | int main() 26 | { 27 | Init(); 28 | 29 | int t = 0; 30 | cin >> t; 31 | 32 | for (int i = 0; i < t; ++i) 33 | { 34 | int num1, num2; 35 | cin >> num1 >> num2; 36 | 37 | cout << CombinationCount(num1, num2) << "\n"; 38 | } 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /YangWooSong/week-03/10816.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | vector origin_vector; 7 | 8 | void Init() 9 | { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | cout.tie(NULL); 13 | } 14 | 15 | int main() 16 | { 17 | Init(); 18 | 19 | int n = 0; 20 | cin >> n; 21 | 22 | vector test_vector; 23 | 24 | for (int a, i = 0; i < n; ++i) 25 | { 26 | cin >> a; 27 | origin_vector.push_back(a); 28 | } 29 | 30 | sort(origin_vector.begin(), origin_vector.end()); 31 | 32 | int m = 0; 33 | cin >> m; 34 | for (int a, i = 0; i < m; ++i) 35 | { 36 | cin >> a; 37 | test_vector.push_back(a); 38 | } 39 | 40 | for (int i = 0; i < m; ++i) 41 | { 42 | cout << upper_bound(origin_vector.begin(), origin_vector.end(), test_vector[i]) - lower_bound(origin_vector.begin(), origin_vector.end(), test_vector[i]) << " "; 43 | } 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /YangWooSong/week-03/10972.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int n; 7 | vector input_vector; 8 | 9 | void Init() { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | cout.tie(NULL); 13 | } 14 | 15 | int main() 16 | { 17 | Init(); 18 | 19 | cin >> n; 20 | for (int num, i = 0; i < n; ++i) 21 | { 22 | cin >> num; 23 | input_vector.push_back(num); 24 | } 25 | 26 | if (next_permutation(input_vector.begin(), input_vector.end())) 27 | { 28 | for (int i = 0; i < input_vector.size(); ++i) 29 | { 30 | cout << input_vector[i] << " "; 31 | } 32 | } 33 | else 34 | cout << "-1"; 35 | 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /YangWooSong/week-03/15649.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogi-rogi/algorithm-class/7881e23c93e5a12f9998927128c4e3ba7468cf8c/YangWooSong/week-03/15649.cpp -------------------------------------------------------------------------------- /YangWooSong/week-03/15650.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int n, m; 5 | int arr[9] = {}; 6 | bool visited[9] = { false }; 7 | 8 | void Dfs(int num, int count) 9 | { 10 | if (count == m) 11 | { 12 | for (int i = 0; i < m; ++i) 13 | { 14 | cout << arr[i] << " "; 15 | } 16 | cout << "\n"; 17 | return; 18 | } 19 | 20 | for (int i = num; i <= n; ++i) 21 | { 22 | if (visited[i] == false) 23 | { 24 | visited[i] = true; 25 | arr[count] = i; 26 | Dfs(i+1, count+1); 27 | visited[i] = false; 28 | } 29 | } 30 | } 31 | 32 | int main() 33 | { 34 | cin >> n >> m; 35 | Dfs(1, 0); 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /YangWooSong/week-03/1654.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void Init() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | } 11 | 12 | int main() 13 | { 14 | Init(); 15 | 16 | int k = 0; 17 | int n = 0; 18 | unsigned int rope_max = 0; 19 | vector ropes; 20 | 21 | cin >> k >> n; 22 | 23 | for (int i = 0; i < k; ++i) 24 | { 25 | unsigned int a = 0; 26 | cin >> a; 27 | ropes.push_back(a); 28 | 29 | if (a > rope_max) 30 | rope_max = a; 31 | } 32 | 33 | unsigned int low = 1; 34 | unsigned int high = rope_max; 35 | unsigned int answer = 0; 36 | 37 | while (low <= high) 38 | { 39 | unsigned int mid = (low + high) / 2; 40 | unsigned int count = 0; 41 | 42 | for (int i = 0; i < ropes.size(); ++i) 43 | { 44 | count += ropes[i] / mid; 45 | } 46 | 47 | if (count < n) 48 | { 49 | high = mid - 1; 50 | } 51 | else 52 | { 53 | low = mid + 1; 54 | answer = max(answer, mid); 55 | } 56 | } 57 | 58 | cout << answer; 59 | 60 | return 0; 61 | } -------------------------------------------------------------------------------- /YangWooSong/week-03/1920.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | vector origin_vector; 7 | 8 | void Init() 9 | { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | cout.tie(NULL); 13 | } 14 | 15 | void Check(int num) 16 | { 17 | int mid = origin_vector.size() / 2; 18 | int left = 0; 19 | int right = origin_vector.size() - 1; 20 | bool is_in = false; 21 | while (left <= right) 22 | { 23 | if (num < origin_vector[mid]) 24 | { 25 | right = mid - 1; 26 | mid = (left + right) / 2; 27 | } 28 | else if (num > origin_vector[mid]) 29 | { 30 | left = mid + 1; 31 | mid = (left + right) / 2; 32 | } 33 | else 34 | { 35 | is_in = true; 36 | break; 37 | } 38 | } 39 | 40 | if (is_in) 41 | cout << "1\n"; 42 | else 43 | cout << "0\n"; 44 | } 45 | 46 | int main() 47 | { 48 | Init(); 49 | 50 | int n = 0; 51 | cin >> n; 52 | 53 | vector test_vector; 54 | 55 | for (int a, i = 0; i < n; ++i) 56 | { 57 | cin >> a; 58 | origin_vector.push_back(a); 59 | } 60 | 61 | sort(origin_vector.begin(), origin_vector.end()); 62 | 63 | int m = 0; 64 | cin >> m; 65 | for (int a, i = 0; i < m; ++i) 66 | { 67 | cin >> a; 68 | test_vector.push_back(a); 69 | } 70 | 71 | for (int i = 0; i < m; ++i) 72 | { 73 | Check(test_vector[i]); 74 | } 75 | 76 | return 0; 77 | } -------------------------------------------------------------------------------- /YangWooSong/week-03/2436.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogi-rogi/algorithm-class/7881e23c93e5a12f9998927128c4e3ba7468cf8c/YangWooSong/week-03/2436.cpp -------------------------------------------------------------------------------- /YangWooSong/week-03/2609.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int GCD(int num1, int num2) 5 | { 6 | int small, big, mod; 7 | big = max(num1, num2); 8 | small = min(num1, num2); 9 | mod = big % small; 10 | 11 | int gcd = 0; 12 | 13 | if (mod == 0) 14 | gcd = small; 15 | else 16 | { 17 | gcd = GCD(small, mod); 18 | } 19 | 20 | return gcd; 21 | } 22 | 23 | int LCM(int num1, int num2, int gcd) 24 | { 25 | return (num1 * num2 / gcd); 26 | } 27 | 28 | int main() 29 | { 30 | int num1, num2; 31 | cin >> num1 >> num2; 32 | 33 | int gcd = GCD(num1, num2); 34 | cout << gcd << "\n"; 35 | cout << LCM(num1, num2, gcd); 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /YangWooSong/week-03/31803.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void Init() { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | } 11 | 12 | double HalfFactorial(int n) { 13 | double result = 1; 14 | int divide_count = 0; 15 | for (int i = n; i > n/2; --i) { 16 | result *= i; 17 | if (divide_count < n / 2) 18 | { 19 | result /= 2.0f; 20 | divide_count++; 21 | } 22 | } 23 | 24 | return result; 25 | } 26 | 27 | long long CountPairings(int n) { 28 | if (n % 2 == 0) { 29 | return HalfFactorial(n); 30 | } 31 | else { 32 | return HalfFactorial(n-1) * n; 33 | } 34 | } 35 | int main() { 36 | Init(); 37 | int n; 38 | cin >> n; 39 | 40 | cout << CountPairings(n) << "\n"; 41 | return 0; 42 | } -------------------------------------------------------------------------------- /YangWooSong/week-03/9613.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void Init() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | } 11 | 12 | int GCD(int num1, int num2) 13 | { 14 | int small, big, mod; 15 | big = max(num1, num2); 16 | small = min(num1, num2); 17 | mod = big % small; 18 | 19 | int gcd = 0; 20 | 21 | if (mod == 0) 22 | gcd = small; 23 | else 24 | { 25 | gcd = GCD(small, mod); 26 | } 27 | 28 | return gcd; 29 | } 30 | 31 | int main() 32 | { 33 | Init(); 34 | 35 | int t = 0; 36 | cin >> t; 37 | 38 | while (t > 0) 39 | { 40 | int n = 0; 41 | cin >> n; 42 | 43 | vector input_vector(n); 44 | for (int i = 0; i < n; ++i) 45 | { 46 | cin >> input_vector[i]; 47 | } 48 | 49 | long long sum = 0; 50 | for (int i = 0; i < n-1; ++i) 51 | { 52 | for (int j = i + 1; j < n; ++j) 53 | { 54 | sum += (long long)GCD(input_vector[i], input_vector[j]); 55 | } 56 | } 57 | cout << sum << "\n"; 58 | 59 | --t; 60 | } 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /YangWooSong/week-04/10799.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogi-rogi/algorithm-class/7881e23c93e5a12f9998927128c4e3ba7468cf8c/YangWooSong/week-04/10799.cpp -------------------------------------------------------------------------------- /YangWooSong/week-04/11286.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void Init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | struct cmp { 14 | bool operator()(int a, int b) { 15 | if (abs(a) == abs(b)) 16 | return a > b; 17 | return abs(a) > abs(b); 18 | } 19 | }; 20 | 21 | int main() { 22 | Init(); 23 | 24 | int n = 0; 25 | cin >> n; 26 | 27 | priority_queue, cmp> q; 28 | for (int a, i = 0; i < n; ++i) 29 | { 30 | cin >> a; 31 | 32 | if (a == 0) { 33 | if (q.size() == 0) 34 | cout << 0 << "\n"; 35 | else 36 | { 37 | cout << q.top() << "\n"; 38 | q.pop(); 39 | } 40 | } 41 | else 42 | q.push(a); 43 | } 44 | return 0; 45 | } -------------------------------------------------------------------------------- /YangWooSong/week-04/1158.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | void Init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | 13 | int main() 14 | { 15 | Init(); 16 | 17 | int n, k; 18 | cin >> n >> k; 19 | 20 | queue num_list; 21 | 22 | for (int i = 0; i < n; ++i) 23 | { 24 | num_list.push(i + 1); 25 | } 26 | 27 | cout << "<"; 28 | 29 | int index = 0; 30 | 31 | while (num_list.size() > 1) 32 | { 33 | index++; 34 | if (index == k) 35 | { 36 | cout << num_list.front() << ", "; 37 | num_list.pop(); 38 | index = 0; 39 | } 40 | else 41 | { 42 | int a = num_list.front(); 43 | num_list.push(a); 44 | num_list.pop(); 45 | } 46 | } 47 | 48 | cout << num_list.front(); 49 | 50 | cout << ">"; 51 | return 0; 52 | } -------------------------------------------------------------------------------- /YangWooSong/week-04/1463.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | int n; 9 | cin >> n; 10 | 11 | queue> save; 12 | save.push({ n, 0 }); 13 | 14 | while (save.front().first > 1) 15 | { 16 | int num = save.front().first; 17 | int count = save.front().second; 18 | 19 | if (num % 3 == 0) 20 | { 21 | save.push({ num / 3, count + 1 }); 22 | } 23 | if (num % 2 == 0) 24 | { 25 | save.push({ num / 2, count + 1 }); 26 | } 27 | 28 | save.push({ num-1, count+1 }); 29 | 30 | 31 | save.pop(); 32 | } 33 | 34 | cout << save.front().second; 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /YangWooSong/week-04/1927.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void Init() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | } 11 | 12 | int main() { 13 | Init(); 14 | 15 | int n = 0; 16 | cin >> n; 17 | 18 | priority_queue, greater> q; 19 | for (int a, i = 0; i < n; ++i) 20 | { 21 | cin >> a; 22 | 23 | if (a == 0) { 24 | if (q.size() == 0) 25 | cout << 0 << "\n"; 26 | else 27 | { 28 | cout << q.top() << "\n"; 29 | q.pop(); 30 | } 31 | } 32 | else 33 | q.push(a); 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /YangWooSong/week-04/1935.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogi-rogi/algorithm-class/7881e23c93e5a12f9998927128c4e3ba7468cf8c/YangWooSong/week-04/1935.cpp -------------------------------------------------------------------------------- /YangWooSong/week-04/2346.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | deque> q; 6 | 7 | int main() { 8 | int n = 0; 9 | cin >> n; 10 | 11 | for (int a, i = 0; i < n; ++i) 12 | { 13 | cin >> a; 14 | q.push_back({a,i}); 15 | } 16 | 17 | int count = q.front().first; 18 | cout << q.front().second << " "; 19 | q.pop_front(); 20 | 21 | while (q.empty() == false) 22 | { 23 | if (count == 1) { 24 | count = q.front().first; 25 | cout << q.front().second << " "; 26 | q.pop_front(); 27 | } 28 | else if (count == -1) { 29 | count = q.back().first; 30 | cout << q.back().second << " "; 31 | q.pop_back(); 32 | } 33 | else if (count > 0) 34 | { 35 | q.push_back(q.front()); 36 | q.pop_front(); 37 | count--; 38 | } 39 | else if (count < 0) { 40 | q.push_front(q.back()); 41 | q.pop_back(); 42 | count++; 43 | } 44 | } 45 | return 0; 46 | } -------------------------------------------------------------------------------- /YangWooSong/week-04/2800.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogi-rogi/algorithm-class/7881e23c93e5a12f9998927128c4e3ba7468cf8c/YangWooSong/week-04/2800.cpp -------------------------------------------------------------------------------- /YangWooSong/week-1/01476.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void init() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | } 10 | 11 | int main() 12 | { 13 | init(); 14 | 15 | int iInput[3] = {}; 16 | int iCal[3] = {}; 17 | int iCount = 0; 18 | 19 | cin >> iInput[0] >> iInput[1] >> iInput[2]; 20 | 21 | while (1) 22 | { 23 | if ((iCal[0] != iInput[0]) || (iCal[1] != iInput[1]) || (iCal[2] != iInput[2])) 24 | { 25 | if (iCal[0] < 15) 26 | iCal[0]++; 27 | else 28 | iCal[0] = 1; 29 | 30 | if (iCal[1] < 28) 31 | iCal[1]++; 32 | else 33 | iCal[1] = 1; 34 | 35 | if (iCal[2] < 19) 36 | iCal[2]++; 37 | else 38 | iCal[2] = 1; 39 | 40 | iCount++; 41 | 42 | } 43 | else 44 | break; 45 | } 46 | 47 | cout << iCount; 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /YangWooSong/week-1/1018.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogi-rogi/algorithm-class/7881e23c93e5a12f9998927128c4e3ba7468cf8c/YangWooSong/week-1/1018.cpp -------------------------------------------------------------------------------- /YangWooSong/week-1/11004.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void init() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | cout.tie(NULL); 11 | } 12 | int main() 13 | { 14 | init(); 15 | 16 | int Count = 0; 17 | int index = 0; 18 | cin >> Count >> index; 19 | 20 | vector vInput; 21 | 22 | for (int a, i = 0; i < Count; ++i) 23 | { 24 | cin >> a; 25 | vInput.push_back(a); 26 | } 27 | 28 | sort(vInput.begin(), vInput.end()); 29 | 30 | cout << vInput[index-1]; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /YangWooSong/week-1/11651.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | struct Inform 7 | { 8 | int first = 0; 9 | int second = 0; 10 | }; 11 | 12 | bool Compare(Inform& a, Inform& b) 13 | { 14 | if (a.second == b.second) 15 | { 16 | return a.first < b.first; 17 | } 18 | else 19 | return a.second < b.second; 20 | } 21 | 22 | void Init() 23 | { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(NULL); 26 | cout.tie(NULL); 27 | } 28 | 29 | int main() 30 | { 31 | Init(); 32 | 33 | vector vList; 34 | 35 | int Count = 0; 36 | cin >> Count; 37 | 38 | for (int i = 0; i < Count; ++i) 39 | { 40 | Inform p; 41 | cin >> p.first >> p.second; 42 | vList.push_back(p); 43 | } 44 | 45 | sort(vList.begin(), vList.end(), Compare); 46 | 47 | for (int i = 0; i < Count; ++i) 48 | { 49 | cout << vList[i].first << " " << vList[i].second << "\n"; 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /YangWooSong/week-1/18870.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | void init() 9 | { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | cout.tie(NULL); 13 | } 14 | int main() 15 | { 16 | init(); 17 | 18 | int Count = 0; 19 | cin >> Count; 20 | 21 | vector vOriginInput; 22 | 23 | for (int a, i = 0; i < Count; ++i) 24 | { 25 | cin >> a; 26 | vOriginInput.push_back(a); 27 | } 28 | 29 | //중복 제거 후 정렬 30 | set setList; 31 | for(auto& iter: vOriginInput) 32 | { 33 | setList.insert(iter); 34 | } 35 | 36 | //딕셔너리 생성 및 출력 37 | map dict; 38 | int tmp = 0; 39 | for (auto& iter : setList) 40 | { 41 | dict[iter] = tmp; 42 | ++tmp; 43 | } 44 | 45 | for (auto& iter : vOriginInput) 46 | { 47 | cout << dict[iter] << " "; 48 | } 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /YangWooSong/week-1/2309.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | cout.tie(NULL); 12 | 13 | int Sum = 0; 14 | vector HeightList; 15 | for (int i = 0; i < 9; ++i) 16 | { 17 | int n = 0; 18 | cin >> n; 19 | HeightList.push_back(n); 20 | Sum += HeightList[i]; 21 | } 22 | 23 | sort(HeightList.begin(), HeightList.end()); 24 | 25 | int notReal1 = 0, notReal2 = 0; 26 | 27 | for (int i = 0; i < 8; ++i) 28 | { 29 | for (int j = i + 1; j < 9; ++j) 30 | { 31 | if (Sum - HeightList[i] - HeightList[j] == 100) 32 | { 33 | notReal1 = i; 34 | notReal2 = j; 35 | break; 36 | } 37 | } 38 | } 39 | 40 | for (int i = 0; i < 9; ++i) 41 | { 42 | if (i != notReal1 && i != notReal2) 43 | cout << HeightList[i] << "\n"; 44 | } 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /YangWooSong/week-1/2751.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | cout.tie(NULL); 12 | 13 | int Count = 0; 14 | cin >> Count; 15 | 16 | vector vNum; 17 | 18 | for (int i = 0; i < Count; ++i) 19 | { 20 | int a = 0; 21 | cin >> a; 22 | vNum.push_back(a); 23 | } 24 | 25 | sort(vNum.begin(), vNum.end()); 26 | 27 | for (int i = 0; i < Count; ++i) 28 | { 29 | cout << vNum[i] << "\n"; 30 | } 31 | 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /asj777/week-01/1018.py: -------------------------------------------------------------------------------- 1 | # 25.03.20 C++ -> Python(Data Science) 코드 연습 2 | # 체스판 다시 칠하기(브루트 포스) 3 | 4 | N,M = map(int,input().split()) 5 | 6 | arr = [input() for i in range(N)] 7 | ans = [] 8 | 9 | for a in range(N-7): 10 | for b in range(M-7): 11 | white = 0 #W로 시작 12 | black = 0 #B로 시작 13 | for i in range(a,a+8): # 자른 범위에서 부터 +8 14 | for j in range(b,b+8): 15 | if((i+j)%2==0): # 짝수(W) 16 | if(arr[i][j]!='W'): # black라면 17 | white+=1 18 | else: 19 | black+=1 20 | else: # 홀수(B) 21 | if(arr[i][j]!='B'): # white라면 22 | white+=1 23 | else: 24 | black+=1 25 | ans.append(white) 26 | ans.append(black) 27 | 28 | print(min(ans)) 29 | 30 | -------------------------------------------------------------------------------- /asj777/week-01/11004.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.03.11 K번쨰 수 (정렬) 5 | long long N,K; 6 | long long arr[5000005]; 7 | 8 | int main() { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> N >> K; 13 | for(int i=0; i> arr[i]; 15 | } 16 | sort(arr,arr+N); 17 | 18 | cout << arr[K-1]; 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /asj777/week-01/11004.py: -------------------------------------------------------------------------------- 1 | # 25.03.22 C++ -> Python(Data Science) 코드 연습 2 | # K번쨰 수 3 | 4 | N,K = map(int,input().split()) 5 | 6 | arr = list(map(int,input().split())) 7 | 8 | arr = sorted(arr) 9 | print(arr[K-1]) 10 | 11 | -------------------------------------------------------------------------------- /asj777/week-01/11651.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.03.22 좌표 정렬하기 2 (정렬) 5 | int N; 6 | vector> v(0); 7 | 8 | bool my_sort(vector& a,vector& b) { 9 | if(a[1]==b[1]) return a[0] < b[0]; 10 | return a[1]> N; 18 | for(int i=0; i> x >> y; 21 | v.push_back({x,y}); 22 | } 23 | 24 | sort(v.begin(),v.end(),my_sort); 25 | 26 | for(auto idx: v) { 27 | cout << idx[0] << " " << idx[1] << "\n"; 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /asj777/week-01/11651.py: -------------------------------------------------------------------------------- 1 | # 25.03.22 C++ -> Python(Data Science) 코드 연습 2 | # 좌표 정렬하기2 (정렬) 3 | 4 | N = int(input()) 5 | 6 | arr = [list(map(int,input().split())) for _ in range(N)] 7 | 8 | arr.sort(key = lambda tmp:(tmp[1],tmp[0])) 9 | for idx in arr: 10 | print(idx[0], idx[1]) 11 | -------------------------------------------------------------------------------- /asj777/week-01/1476.py: -------------------------------------------------------------------------------- 1 | # 25.03.18 C++ -> Python(Data Science) 코드 연습 2 | # 날짜 계산 (브루트 포스) 3 | 4 | E,S,M = map(int,input().split()) 5 | e,s,m = 1,1,1 # 지구 태양 달 tmp 6 | year = 1 7 | 8 | while(1): 9 | if(e==E and s==S and m ==M): 10 | print(year) 11 | break 12 | 13 | e+=1 14 | s+=1 15 | m+=1 16 | year+=1 17 | 18 | if(e>15): 19 | e = 1 20 | if(s>28): 21 | s = 1 22 | if(m>19): 23 | m = 1 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /asj777/week-01/18770.py: -------------------------------------------------------------------------------- 1 | # 25.03.22 C++ -> Python(Data Science) 코드 연습 2 | # 좌표 압축 (정렬) 3 | 4 | N = int(input()) 5 | 6 | arr = list(map(int,input().split())) # 입력 7 | 8 | X = sorted(set(arr)) # 중복제거 9 | 10 | sort_X = {val: idx for idx, val in enumerate(X)} #인덱스 매핑 과정? 11 | 12 | print(*[sort_X[i] for i in arr]) #원본 arr에 대해 해당 값에 대한 인덱스 찾기 13 | -------------------------------------------------------------------------------- /asj777/week-01/1978.py: -------------------------------------------------------------------------------- 1 | # 25.03.18 C++ -> Python(Data Science) 코드 연습 2 | # 소수 찾기 3 | 4 | def prime(n): 5 | if(n<2): 6 | return False 7 | for i in range(2,(int)(n**0.5)+1): 8 | if(n%i==0): 9 | return False 10 | return True 11 | 12 | N = int(input()) 13 | arr = list(map(int,input().split())) 14 | 15 | 16 | cnt = 0 17 | for i in range(N): 18 | if(prime(arr[i])): 19 | cnt+=1 20 | 21 | print(cnt) 22 | -------------------------------------------------------------------------------- /asj777/week-01/2309.py: -------------------------------------------------------------------------------- 1 | # 25.03.18 C++ -> Python(Data Science) 코드 연습 2 | # 일곱난쟁이 (브루트 포스) 3 | 4 | arr = [int(input())for _ in range(9)] 5 | arr = sorted(arr) 6 | 7 | for i in range(8): # 0부터 7까지 8 | for j in range(i+1,9): # i+1부터 최대 8까지 9 | if(sum(arr) - arr[i]-arr[j]==100): 10 | first = arr[i] #첫번쨰 11 | second = arr[j] #두번쨰 12 | break 13 | 14 | arr.remove(first) # 지우기 15 | arr.remove(second) 16 | 17 | for i in arr: 18 | print(i) 19 | -------------------------------------------------------------------------------- /asj777/week-02/10814.py: -------------------------------------------------------------------------------- 1 | # 25.03.24 C++ -> Python(Data Science) 코드 연습 2 | # 나이순 정렬 (정렬) 3 | 4 | N = int(input()) 5 | arr = [input().split() for _ in range(N)] 6 | 7 | arr.sort(key=lambda x: (int(x[0]))) #람다 함수를 이용해 나이순 정렬 8 | 9 | for i,j in arr: 10 | print(i + " " + j) 11 | -------------------------------------------------------------------------------- /asj777/week-02/10989.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | N = int(sys.stdin.readline()) 4 | 5 | arr = [0] * 10001 6 | 7 | for _ in range(N): 8 | num = int(sys.stdin.readline()) 9 | arr[num] += 1 10 | 11 | 12 | for i in range(1, 10001): 13 | if arr[i] > 0: 14 | for _ in range(arr[i]): 15 | print(i) 16 | -------------------------------------------------------------------------------- /asj777/week-02/11650.py: -------------------------------------------------------------------------------- 1 | #from math import gcd,lcm 2 | 3 | # 25.03.27 C++ -> Python(Data Science) 코드 연습 4 | # 좌표 정렬하기 (정렬) 5 | 6 | N= int(input()) 7 | 8 | arr = [tuple(map(int,input().split())) for _ in range(N)] 9 | 10 | 11 | arr.sort(key = lambda x : (x[0],x[1])) 12 | for i,j in arr: 13 | print(i, j) 14 | -------------------------------------------------------------------------------- /asj777/week-02/1676.py: -------------------------------------------------------------------------------- 1 | # 25.03.24 C++ -> Python(Data Science) 코드 연습 2 | # 팩토리얼 0의 개수 (정렬) 3 | 4 | N = int(input()) 5 | 6 | cnt = 0 7 | mod = 5 8 | while N>=mod: 9 | cnt += N//mod 10 | mod *=5 11 | 12 | print((int)(cnt)) 13 | -------------------------------------------------------------------------------- /asj777/week-02/17478.py: -------------------------------------------------------------------------------- 1 | def recursive(x, cnt): 2 | query = "____" * cnt 3 | print(query + "\"재귀함수가 뭔가요?\"") 4 | 5 | if x == 0: 6 | print(query + "\"재귀함수는 자기 자신을 호출하는 함수라네\"") 7 | else: 8 | print(query + "\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.") 9 | print(query + "마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.") 10 | print(query + "그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\"") 11 | 12 | recursive(x - 1, cnt + 1) 13 | 14 | print(query + "라고 답변하였지.") 15 | 16 | N = int(input()) 17 | 18 | print("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.") 19 | recursive(N, 0) 20 | -------------------------------------------------------------------------------- /asj777/week-02/1929.py: -------------------------------------------------------------------------------- 1 | # 25.03.24 C++ -> Python(Data Science) 코드 연습 2 | # 소수 구하기 (수학) 3 | 4 | 5 | def seive(m,n): 6 | arr = [True] * (n+1) 7 | arr[0]=arr[1]=0 8 | for i in range(2,int(n**0.5)+1): 9 | if(arr[i]): 10 | for j in range(i*i,n+1,i): 11 | arr[j] = 0 12 | 13 | for i in range(m,n+1): 14 | if(arr[i]): 15 | print(i) 16 | 17 | M,N= map(int,input().split()) 18 | seive(M,N) 19 | -------------------------------------------------------------------------------- /asj777/week-02/1931.py: -------------------------------------------------------------------------------- 1 | # 25.03.24 C++ -> Python(Data Science) 코드 연습 2 | # 회의실 배정 (그리디) 3 | 4 | N = int(input()) 5 | arr = [list(map(int,input().split())) for _ in range(N)] 6 | 7 | 8 | cnt = 0 # 개수, 종료 시간 9 | end = 0 10 | #1. 종료 시간이 짧을수록, 2. 빠른 시작시간 순으로 11 | arr.sort(key = lambda x : (x[1],x[0])) 12 | 13 | 14 | for s,e in arr: 15 | if(s>=end): #종료시간을 넘어가면 16 | end = e #종료시간 갱신 17 | cnt+=1 #및 추가 18 | 19 | print(cnt) 20 | -------------------------------------------------------------------------------- /asj777/week-02/2139.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.03.24 나는 너가 살아온 날을 알고 있다 5 | 6 | int D, M, Y; 7 | int daylist[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 8 | 9 | // 윤년 판별 함수 10 | bool is_year(int y) { 11 | if (y % 4 == 0) { 12 | if (y % 100 == 0) { 13 | if (y % 400 == 0) return true; 14 | return false; 15 | } 16 | return true; 17 | } 18 | return false; 19 | } 20 | 21 | 22 | int solve(int d, int m, int y) { 23 | int calcul = 0; 24 | 25 | for (int i = 1; i < m; i++) { 26 | calcul += daylist[i]; 27 | } 28 | 29 | calcul += d; 30 | 31 | if (is_year(y) && m > 2) { 32 | calcul += 1; 33 | } 34 | 35 | return calcul; 36 | } 37 | 38 | int main() { 39 | ios::sync_with_stdio(0); 40 | cin.tie(0); 41 | 42 | while (1) { 43 | cin >> D >> M >> Y; 44 | if (D == 0 && M == 0 && Y == 0) break; 45 | cout << solve(D, M, Y) << "\n"; 46 | } 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /asj777/week-02/2231.py: -------------------------------------------------------------------------------- 1 | # 25.03.24 C++ -> Python(Data Science) 코드 연습 2 | # 분해합 (수학) 3 | 4 | def divide(n): 5 | for i in range(1,n+1): 6 | tmp = i + sum(map(int,str(i))) #각 숫자를 파싱(분해)후 더하기(자릿수 별 더하기) 7 | if(tmp==n): 8 | return i 9 | return 0 10 | 11 | N = int(input()) 12 | print(divide(N)) 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /asj777/week-02/26265.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.03.24 멘토와 멘티 5 | int N; 6 | vector> v; 7 | bool compare(const pair &a ,const pair &b) { 8 | if(a.first == b.first) { 9 | return a.second>b.second; 10 | } 11 | return a.first < b.first; 12 | } 13 | 14 | int main() { 15 | ios::sync_with_stdio(0); 16 | cin.tie(0); 17 | 18 | cin >> N; 19 | for(int i=0; i> mento >> menti; 22 | v.push_back({mento,menti}); 23 | } 24 | 25 | sort(v.begin(),v.end(),compare); 26 | for (auto mem: v) { 27 | cout << mem.first << " " << mem.second << "\n"; 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /asj777/week-02/2775.py: -------------------------------------------------------------------------------- 1 | # 25.03.24 C++ -> Python(Data Science) 코드 연습 2 | # 부녀회장이 될꺼야 (다이나믹 프로그래밍) 3 | 4 | dp = [[0]* 15 for _ in range(15)] #리스트 컴프리헨션 -->pythonic code need practice! 5 | 6 | for i in range(1,15): 7 | dp[0][i] = i 8 | 9 | for i in range(1,15): 10 | for j in range(1,15): 11 | dp[i][j] = dp[i-1][j] + dp[i][j-1] 12 | 13 | T = int(input()) 14 | 15 | for _ in range(T): 16 | k = int(input()) 17 | n = int(input()) 18 | print(dp[k][n]) 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /asj777/week-02/28702.py: -------------------------------------------------------------------------------- 1 | import sys 2 | # 25.03.27 C++ -> Python(Data Science) 코드 연습 3 | # FizzBuzz (수학) 4 | 5 | for i in range(3,0,-1): 6 | st = (sys.stdin.readline().strip()) 7 | if st not in ["Fizz","Buzz","FizzBuzz"]: 8 | n = int(st) + i 9 | 10 | if(n%15==0): 11 | print("FizzBuzz") 12 | elif(n%3==0): 13 | print("Fizz") 14 | elif(n%5==0): 15 | print("Buzz") 16 | else: 17 | print(n) 18 | -------------------------------------------------------------------------------- /asj777/week-02/31067.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.03.24 다오의 경주 대회 5 | 6 | int N,K; 7 | int track[100005]; 8 | int tmp[100005]; 9 | 10 | int main() { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> N >> K; 15 | for(int i=0; i> track[i]; 17 | } 18 | int base = track[0]; 19 | int cnt = 0; 20 | for(int i=1; ibase) continue; 22 | else { 23 | track[i]+=K; 24 | cnt++; 25 | } 26 | base = max(base,track[i]); 27 | } 28 | 29 | for(int i=0; i=track[i+1]) { 31 | cout << -1; 32 | return 0; 33 | } 34 | } 35 | 36 | cout << cnt; 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /asj777/week-02/4153.py: -------------------------------------------------------------------------------- 1 | # 25.03.25 C++ -> Python(Data Science) 코드 연습 2 | # 직각삼각형 (수학) 3 | 4 | def is_Tri(a,b,c): 5 | if(a**2+b**2==c**2): 6 | return True 7 | return False 8 | 9 | while(1): 10 | a,b,c = map(int,input().split()) 11 | if(a ==0 and b==0 and c ==0): 12 | break 13 | 14 | a,b,c = sorted([a,b,c]) #정렬 15 | 16 | if(is_Tri(a,b,c)): 17 | print("right") 18 | else: 19 | print("wrong") 20 | 21 | -------------------------------------------------------------------------------- /asj777/week-02/4421.py: -------------------------------------------------------------------------------- 1 | # 25.03.23 C++ -> Python(Data Science) 코드 연습 2 | # 로프 (그리디) 3 | 4 | N = int(input()) 5 | arr = [int(input()) for _ in range(N)] 6 | # O(n log n) 7 | arr.sort(reverse=True) # arr.reverse()는 단순히 뒤집기만 한다 O(n)연산 8 | weight = 0 9 | 10 | for i in range(N): 11 | weight = max(weight,arr[i]*(i+1)) 12 | 13 | print(weight) 14 | -------------------------------------------------------------------------------- /asj777/week-03/10816.py: -------------------------------------------------------------------------------- 1 | from bisect import bisect_left, bisect_right 2 | # 25.03.25 C++ -> Python(Data Science) 코드 연습 3 | # 수 찾기(이진탐색) 4 | 5 | # lower_bound --> STL lower_bound : 탐색 대상 값 이상이 처음으로 등장하는 위치 6 | # upper_bound --> STL upper_bound : 탐색 대상 값 초과가 처음으로 등장하는 위치 7 | 8 | N = int(input()) 9 | arr = list(map(int,input().split())) 10 | arr.sort() 11 | 12 | M = int(input()) 13 | arr2 = list(map(int,input().split())) 14 | 15 | 16 | for i in arr2: 17 | ans = bisect_right(arr,i) - bisect_left(arr,i) 18 | print(ans) 19 | -------------------------------------------------------------------------------- /asj777/week-03/1920.py: -------------------------------------------------------------------------------- 1 | # 25.03.25 C++ -> Python(Data Science) 코드 연습 2 | # 수 찾기(이진탐색) 3 | 4 | def bineary_search(arr,target): 5 | left = 0 6 | right = len(arr)-1 7 | while(left<=right): 8 | mid = (left+right)//2 9 | if(arr[mid]==target): 10 | return True 11 | elif(arr[mid] 라이브러리 사용 가능 2 | 3 | # 25.03.25 C++ -> Python(Data Science) 코드 연습 4 | # 최대공약수 최소공배수(수학) 5 | 6 | def gcd(a,b): 7 | if(b==0): 8 | return a 9 | return gcd(b,a%b) 10 | 11 | def lcm(a,b): 12 | return a*b // gcd(a,b) 13 | 14 | n,m = map(int,input().split()) 15 | print(gcd(n,m)) 16 | print(lcm(n,m)) 17 | 18 | 19 | -------------------------------------------------------------------------------- /asj777/week-04/10773.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.04.05 제로 복습(스택) 5 | int K; 6 | stack stk; 7 | 8 | int main() { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> K; 13 | while(K--) { 14 | int n; 15 | cin >> n; 16 | if(n!=0) { 17 | stk.push(n); 18 | } 19 | else { 20 | stk.pop(); 21 | } 22 | } 23 | 24 | int ans= 0; 25 | while(!stk.empty()) { 26 | ans += stk.top(); 27 | stk.pop(); 28 | } 29 | 30 | cout << ans; 31 | return 0; 32 | } 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /asj777/week-04/10799.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.04.02 쇠막대기 복습(스택) 5 | string str; 6 | int cnt = 0; 7 | stack stk; 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> str; 14 | 15 | for(int i=0; i 2 | using namespace std; 3 | 4 | // 25.04.02 요세푸스 문제 복습 (큐) 5 | int N,K; 6 | queue q; 7 | vector ans; // 결과 배열 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> N >> K; 14 | 15 | for(int i=1; i<=N; i++) { 16 | q.push(i); 17 | } // 미리 넣기 18 | 19 | while(!q.empty()) { 20 | for(int i=0; i"; 36 | 37 | 38 | return 0; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /asj777/week-04/1463.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.04.02 1로 만들기 복습 (큐) 5 | int N; 6 | queue> q; 7 | int cnt = 0; 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> N; 14 | 15 | q.push({N,cnt}); // 값 연산 횟수 16 | 17 | while(!q.empty()) { 18 | int num = q.front().first; 19 | int tmp = q.front().second; 20 | q.pop(); 21 | 22 | if(num==1) { 23 | cout << tmp; 24 | break; 25 | } 26 | else { 27 | if(num%3==0) { 28 | q.push({num/3,tmp+1}); 29 | } 30 | if(num%2==0) { 31 | q.push({num/2,tmp+1}); 32 | } 33 | q.push({num-1,tmp+1}); 34 | } 35 | 36 | } 37 | 38 | return 0; 39 | 40 | } 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /asj777/week-04/1927.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.04.02 최소 힙 복습 (우선순위 큐) 5 | int N; 6 | priority_queue,greater> pq; 7 | 8 | int main() { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> N; 13 | 14 | while(N--) { 15 | int x; 16 | cin >> x; 17 | 18 | if(x!=0) { 19 | pq.push(x); 20 | } 21 | else { 22 | if(pq.empty()) { 23 | cout << 0 << "\n"; 24 | } 25 | else { 26 | cout << pq.top() << '\n'; 27 | pq.pop(); 28 | } 29 | } 30 | } 31 | 32 | return 0; 33 | 34 | } 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /asj777/week-04/1935.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.04.02 후위 표기식2 복습(스택) 5 | int N; 6 | map mp; 7 | string str; 8 | stack stk; 9 | 10 | int main() { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | 15 | cin >> N; 16 | 17 | cin >> str; 18 | 19 | for(int i=0; i> val; 22 | mp['A'+ i] = val; 23 | } 24 | 25 | for(int i=0; i='A'&& str[i]<='Z') { 27 | stk.push(mp[str[i]]); 28 | } 29 | else { 30 | double b = stk.top(); stk.pop(); 31 | double a = stk.top(); stk.pop(); 32 | 33 | if(str[i]=='+') { 34 | stk.push(a+b); 35 | } 36 | else if(str[i]=='-') { 37 | stk.push(a-b); 38 | } 39 | else if(str[i]=='*') { 40 | stk.push(a*b); 41 | } 42 | else if(str[i]=='/') { 43 | stk.push(a/b); 44 | } 45 | } 46 | } 47 | 48 | cout << fixed; 49 | cout.precision(2); 50 | cout << stk.top(); 51 | 52 | return 0; 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /asj777/week-04/4839.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.04.07 안정적인 문자열 (스택) 5 | string str; 6 | 7 | int main() { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int num = 1; 12 | while(1) { 13 | stack stk; 14 | cin >> str; 15 | if(str[0]=='-') break; 16 | int cnt = 0; // 최소 연산 횟수 17 | for(char ch : str) { 18 | if(ch=='{') { 19 | stk.push(ch); 20 | } 21 | else { 22 | if(!stk.empty()&&stk.top()=='{') { 23 | stk.pop(); 24 | } 25 | else { 26 | stk.push('{'); 27 | cnt++; 28 | } 29 | } 30 | } 31 | 32 | cnt += stk.size()/2; 33 | cout << num << ". " << cnt << "\n"; 34 | 35 | num++; 36 | } 37 | return 0; 38 | } 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /asj777/week-04/9935.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 25.04.08 문자열 폭발 (스택) 5 | string str; 6 | string bomb; 7 | 8 | int main() { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> str; 13 | cin >> bomb; 14 | stack stk; 15 | 16 | for(char ch: str) { 17 | stk.push(ch); 18 | 19 | if(stk.size()>=bomb.length()) { 20 | string tmp = ""; 21 | 22 | for(int i=0; i 2 | using namespace std; 3 | // 25.05.02 N으로 만들기 - 백트래킹 4 | string N; 5 | map,int> mp; 6 | 7 | void solve(int left,int right, string cur, setstmp) { 8 | if(cur==N) { 9 | mp[stmp] = 1; 10 | return; 11 | } 12 | if(left>0) { 13 | string nxt = N[left-1]+cur; 14 | stmp.insert(nxt); 15 | solve(left-1,right,nxt,stmp); 16 | stmp.erase(nxt); 17 | } 18 | if(right+1> N; 30 | for(int i=0; i st = {tmp}; 33 | solve(i,i,tmp,st); 34 | } 35 | 36 | cout << mp.size(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /asj777/week-06/2015.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // 25.05.03 수들의 합4 4 | int N; 5 | long long arr[200005]; 6 | long long K; 7 | map mp; 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> N >> K; 14 | long long prefix = 0; // 누적합 prefix[i] = prefix[i-1] + arr[i] 15 | long long ans = 0; 16 | 17 | mp[0] = 1; 18 | 19 | for(int i=1; i<=N; i++) { 20 | cin >> arr[i]; 21 | prefix += arr[i]; 22 | ans += mp[prefix-K]; // 이전에 등장한적 있으면 추가 23 | mp[prefix]++; // 구간합 저장 24 | } 25 | 26 | cout << ans; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /asj777/week-06/21939.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // 25.05.04 문제 추천 시스템 Version 1(복습) 4 | int N,M; 5 | map mp; // 문제번호 -> 난이도 6 | set> st; // 난이도, 문제 번호 7 | 8 | int main() { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> N; 13 | while(N--) { 14 | int P,L; 15 | cin >> P >> L; 16 | mp[P] =L; 17 | st.insert({L,P}); 18 | } 19 | 20 | cin >> M; 21 | while(M--) { 22 | string query; 23 | cin >> query; 24 | if(query == "add") { 25 | int P,L; 26 | cin >> P >> L; 27 | mp[P] = L; 28 | st.insert({L,P}); 29 | } 30 | else if(query == "solved") { 31 | int P; 32 | cin >> P; 33 | int L = mp[P]; 34 | mp.erase(P); 35 | st.erase({L,P}); 36 | } 37 | else if(query == "recommend") { 38 | int x; 39 | cin >> x; 40 | if(x==1) { 41 | auto it = --st.end(); 42 | cout << it->second << "\n"; 43 | } 44 | else if(x==-1) { 45 | auto it = st.begin(); 46 | cout << it->second << "\n"; 47 | } 48 | } 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /asj777/week-06/2910.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // 25.05.02 빈도정렬(복습) - set과 map, 정렬 4 | int N; 5 | long long C; 6 | unordered_map mp; 7 | 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> N >> C; 14 | vector v(N+1,0); 15 | for(int i=0; i> num; 18 | mp[num]++; 19 | if(mp[num]==1) v.push_back(num); 20 | } 21 | 22 | stable_sort(v.begin(),v.end(),[](int a,int b) {return mp[a]>mp[b];}); 23 | 24 | for(auto n : v) { 25 | for(int i=0; i 2 | using namespace std; 3 | // 25.05.010 RGB 거리 (다이나믹 프로그래밍 복습) 4 | int N; 5 | int dp[1005][3]; // red greeen blue 6 | 7 | int main() { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | cin >> N; 12 | for(int i=0; i> dp[i][j]; 15 | } 16 | } 17 | 18 | for(int i=0; i 2 | using namespace std; 3 | // 25.05.07 가장 긴 감소하는 부분 수열 (다이나믹 프로그래밍) 4 | int N; 5 | int arr[1005]; 6 | int dp[1005]; 7 | 8 | int main() { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> N; 13 | for(int i=0; i> arr[i]; 15 | dp[i] = 1; 16 | } 17 | 18 | for(int i=0; iarr[i]) { 21 | dp[i] = max(dp[i],dp[j]+1); 22 | } 23 | } 24 | } 25 | int ans = *max_element(dp,dp+N); 26 | cout << ans; 27 | 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /asj777/week-07/11727.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // 25.05.07 2×n 타일링 2 (다이나믹 프로그래밍 복습) 4 | int N; 5 | const int mod = 10007; 6 | int dp[1005]; 7 | 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> N; 14 | dp[0] = 0; 15 | dp[1] = 1; 16 | dp[2] = 3; 17 | for(int i=3; i<=N; i++) { 18 | dp[i] = dp[i-1] + 2 * (dp[i-2]); 19 | dp[i] %= mod; 20 | } 21 | 22 | cout << dp[N]; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /asj777/week-07/15988.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // 25.05.09 1,2,3 더하기 3 (다이나믹 프로그래밍) 4 | int T,N; 5 | const long long mod = 1000000009; 6 | long long dp[1000005]; 7 | 8 | int main() { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> T; 13 | 14 | dp[0] = 0; 15 | dp[1] = 1; 16 | dp[2] = 2; 17 | dp[3] = 4; 18 | while(T--) { 19 | cin >> N; 20 | for(int i=4; i<=N; i++) { 21 | dp[i] = dp[i-1] +dp[i-2] + dp[i-3]; 22 | dp[i] %= mod; 23 | } 24 | cout << dp[N] << "\n"; 25 | } 26 | 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /asj777/week-07/2294.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // 25.05.11 동전2 (다이나믹 프로그래밍) 4 | int n,k; 5 | int arr[105]; 6 | int dp[10005]; 7 | const int INF = 1e9; 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> n >> k; 14 | for(int i=0; i> arr[i]; 16 | } 17 | fill(dp,dp+k+1,INF); 18 | 19 | dp[0] = 0; // 0원은 0 20 | for(int i=0; i 2 | using namespace std; 3 | // 25.05.07 계단 오르기 (다이나믹 프로그래밍 복습) 4 | int N; 5 | int arr[305]; 6 | int dp[305]; 7 | 8 | int main() { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> N; 13 | for(int i=1; i<=N; i++) { 14 | cin >> arr[i]; 15 | } 16 | dp[0] = 0; // 시작 계단 17 | dp[1] = arr[1]; // 첫번째 18 | dp[2] = arr[1]+arr[2]; // 두번째 19 | dp[3] = max(arr[1]+arr[3],arr[2]+arr[3]); // (1+2) 또는 (1+3) 20 | 21 | for(int i=4; i<=N; i++) { 22 | dp[i] = max(dp[i-2] + arr[i], dp[i-3] + arr[i-1] + arr[i]); // 2칸 올라오기 또는 연속으로 올라오는 경우 23 | } 24 | 25 | cout << dp[N]; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /asj777/week-08/1354.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // 25.05.18 무한 수열2 (다이나믹 프로그래밍) 4 | 5 | long long N, P, Q, X, Y; 6 | map dp; // dp베열을 map으로 접근 7 | 8 | long long solve(long long n) { 9 | if (n <= 0) return 1; // dp[0] = 1 10 | if (dp.count(n)) return dp[n]; // count함수는 map에 존재하는 지 확인 11 | return dp[n] = solve(n / P - X) + solve(n / Q - Y); 12 | } 13 | 14 | int main() { 15 | ios::sync_with_stdio(0); 16 | cin.tie(0); 17 | 18 | cin >> N >> P >> Q >> X >> Y; 19 | cout << solve(N); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /asj777/week-08/16400.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // 25.05.17 소수 화폐 (다이나믹 프로그래밍) 4 | int N; 5 | const long long mod = 123456789; 6 | long long dp[40005]; // 소수를 이용해 N원을 만들 수 있는 경우의 수 7 | vector prime; 8 | 9 | void getPrime(int limit) { 10 | vector v(limit+1,true); 11 | v[0] = v[1] = false; 12 | // 에라스토테네스의 체 13 | for(int i=2; i*i<=limit; i++) { 14 | if(v[i]) { 15 | for(int j= i*i; j<=limit; j+=i) { 16 | v[j] = false; 17 | } 18 | } 19 | } 20 | 21 | for(int i=2; i<=limit; i++) { 22 | if(v[i]) prime.push_back(i); 23 | } 24 | } 25 | 26 | int main() { 27 | ios::sync_with_stdio(0); 28 | cin.tie(0); 29 | 30 | cin >> N; 31 | getPrime(N); 32 | 33 | dp[0] = 1; // 0원을 만들수 없는 경우는 없으므로 1가지 34 | 35 | for(int p : prime) { 36 | for(int i=p; i<=N; i++) { 37 | dp[i] = (dp[i] + dp[i-p]) % mod; 38 | } 39 | } 40 | 41 | cout << dp[N]; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /asj777/week-08/2565.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // 25.05.16 전깃줄 (다이나믹 프로그래밍) 4 | int N; 5 | vector> arr; 6 | int dp[505]; // LIS 끝의 길이는 1 7 | int ans = 1; // LIS 기본길이 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> N; 14 | for(int i=0; i> a >> b; 17 | arr.push_back({a,b}); 18 | } 19 | sort(arr.begin(),arr.end()); // 정렬 필요 20 | 21 | for(int i=0; iarr[j].second) { 25 | dp[i] = max(dp[i],dp[j]+1); 26 | } 27 | } 28 | ans = max(ans,dp[i]); 29 | } 30 | 31 | cout << N-ans; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /asj777/week-08/5557.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // 25.05.19 1학년 (다이나믹 프로그래밍) 4 | int N; 5 | int arr[105]; 6 | long long dp[105][21]; // i번째 까지 고려해서 j가 되는 경우의 수 7 | 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> N; 14 | for(int i=0; i> arr[i]; 16 | } 17 | 18 | dp[0][arr[0]] = 1; // 첫번째 수의 경우는 1개로 고정 19 | 20 | for(int i=1; i=0) dp[i][minus] += dp[i-1][j]; 28 | } 29 | } 30 | } 31 | 32 | cout << dp[N-2][arr[N-1]]; // 마지막 N-1을 수를 만들기 위해서 N-2까지 계산함 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /baektom/week-1/testmd: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /danmoo6837/week-1/01018: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char w[8][8] = { 5 | {'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'}, 6 | {'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'}, 7 | {'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'}, 8 | {'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'}, 9 | {'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'}, 10 | {'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'}, 11 | {'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'}, 12 | {'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'} 13 | }; 14 | 15 | char b[8][8] = { 16 | {'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'}, 17 | {'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'}, 18 | {'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'}, 19 | {'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'}, 20 | {'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'}, 21 | {'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'}, 22 | {'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'}, 23 | {'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'} 24 | }; 25 | 26 | int main(){ 27 | int n, m, min = 64; 28 | 29 | scanf("%d %d", &n, &m); 30 | 31 | //2차원 배열 할당 32 | char **arr = (char **)malloc(sizeof(char*) * n); 33 | for(int i=0;i 2 | #include 3 | 4 | int compar(const void *a, const void *b) { 5 | return (*(int*)a - *(int*)b); 6 | } 7 | 8 | int main() { 9 | int j, k; 10 | int hap =0, arr[9]; 11 | 12 | for(int i=0;i<9;i++){ 13 | scanf("%d", &arr[i]); 14 | hap+=arr[i]; 15 | } 16 | 17 | qsort(arr,9,sizeof(int), compar); 18 | for(k=0;k<9;k++){ 19 | for(j=k+1;j<9;j++){ 20 | int b=arr[j]+arr[k]; 21 | 22 | if(hap-b == 100) { 23 | 24 | for(int i=0;i<9;i++) { 25 | if(i != j && i != k) { 26 | printf("%d\n", arr[i]); 27 | } 28 | } 29 | return 0; 30 | } 31 | } 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /danmoo6837/week-1/2751: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int compar(const void *a, const void *b) { 5 | return (*(int*)a - *(int*)b); 6 | } 7 | 8 | int main() { 9 | int n; 10 | int *arr; 11 | 12 | scanf("%d", &n); 13 | arr = (int*)malloc(sizeof(int)*n); 14 | for(int i=0;i 2 | #include 3 | 4 | typedef struct { 5 | int start; 6 | int end; 7 | } meet; 8 | 9 | int compare(const void *a, const void *b) { 10 | meet *m1 = (meet*) a; 11 | meet *m2 = (meet*) b; 12 | 13 | if(m1->end != m2->end) return m1->end - m2->end; 14 | 15 | return m1->start - m2->start; 16 | } 17 | 18 | int main() { 19 | int n, cnt=0, start_point=0; 20 | scanf("%d", &n); 21 | meet arr[n]; 22 | 23 | for(int i=0;i 2 | #include 3 | 4 | int main() { 5 | int n, k, p,cnt=0; 6 | scanf("%d %d", &n, &k); 7 | 8 | int arr[n+1]; 9 | arr[0] = 0; 10 | arr[1] = 0; 11 | for(int i=2;i 2 | 3 | int main() { 4 | int n, k, cnt=0; 5 | int arr[1000000]; 6 | 7 | scanf("%d %d", &n, &k); 8 | for(int i=0;i=0;i--){ 13 | if(arr[i]<=k) { 14 | cnt += (int)(k/arr[i]); 15 | k %= arr[i]; 16 | } 17 | } 18 | 19 | printf("%d", cnt); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /danmoo6837/week2/11582.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int compare(const void *a, const void *b) { 5 | return *(int *)a - *(int *)b; 6 | } 7 | 8 | int main() { 9 | int n, k; 10 | scanf("%d", &n); 11 | 12 | int arr[n]; 13 | for (int i = 0; i < n; i++) { 14 | scanf("%d", &arr[i]); 15 | } 16 | 17 | scanf("%d", &k); 18 | 19 | int part_size = n / k; 20 | 21 | for (int i = 0; i < n; i += part_size) { 22 | qsort(arr + i, part_size, sizeof(int), compare); 23 | } 24 | 25 | for (int i = 0; i < n; i++) { 26 | printf("%d ", arr[i]); 27 | } 28 | printf("\n"); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /danmoo6837/week2/1747.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int is_prime(int num) { 6 | if(num<2) return 0; 7 | if(num == 2) return 1; 8 | if(num%2 == 0) return 0; 9 | 10 | for(int i=3;i<= sqrt(num); i+=2) { 11 | if( num%i==0) return 0; 12 | } 13 | 14 | return 1; 15 | } 16 | 17 | int is_palindrome(int num) { 18 | char str[10]; 19 | sprintf(str, "%d", num); 20 | int len = strlen(str); 21 | for(int i=0;i 2 | 3 | int recursive_call(int depth, int n); 4 | void func(int cnt); 5 | 6 | int main() { 7 | int depth=0,n; 8 | scanf("%d", &n); 9 | printf("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.\n"); 10 | 11 | recursive_call(depth, n); 12 | return 0; 13 | } 14 | void func(int cnt){ 15 | while(cnt--) printf("____"); 16 | } 17 | 18 | int recursive_call(int depth, int n) { 19 | 20 | func(depth); 21 | printf("\"재귀함수가 뭔가요?\"\n"); 22 | 23 | if(depth == n+1) ; 24 | else if(depth == n) { 25 | func(depth); 26 | printf("\"재귀함수는 자기 자신을 호출하는 함수라네\"\n"); 27 | } 28 | else { 29 | func(depth); 30 | printf("\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.\n"); 31 | func(depth); 32 | printf("마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.\n"); 33 | func(depth); 34 | printf("그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\"\n"); 35 | recursive_call(depth+1, n); 36 | } 37 | func(depth); 38 | printf("라고 답변하였지.\n"); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /danmoo6837/week2/19564.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | char str[100001]; 6 | int cnt=1; 7 | scanf("%s", str); 8 | getchar(); 9 | int len = strlen(str); 10 | for(int i=1;i 2 | #include 3 | 4 | int compare(const void *a, const void *b) { 5 | return (*(int*)a - *(int*)b); 6 | } 7 | 8 | int main() { 9 | int n, w=0; 10 | 11 | scanf("%d", &n); 12 | 13 | int arr[n]; 14 | for(int i=0;i 탐욕 선택 속성, 최적 부분 구조 6 | 7 | 백트레킹 문제가 고난도 문제로 코테 마지막 문제로 8 | 나오는 경우가 꽤 있다. 9 | 10 | 피보나치 수열 이용 11 | 12 | Divide and Conquerd 13 | 1. Divide 14 | 2. Conquer 15 | 3. Combine 16 | 17 | Merge Sort(병합정렬) -------------------------------------------------------------------------------- /kws0315/week-1/BaekJoon-1018.py: -------------------------------------------------------------------------------- 1 | from math import * 2 | from heapq import heappop, heappush 3 | from itertools import combinations 4 | from collections import defaultdict, deque 5 | from bisect import bisect_left, bisect_right 6 | from sys import stdin, setrecursionlimit 7 | from functools import reduce 8 | 9 | input = stdin.readline 10 | setrecursionlimit(10 ** 6) 11 | 12 | INF = int(1e10) 13 | 14 | #백준 1018번 문제: 체스판 다시 칠하기 15 | if __name__ == '__main__': 16 | #Input 17 | N, M = map(int, input().split()) #범위 설정 (가로X세로) 18 | board = [input().rstrip() for _ in range(N)] 19 | 20 | #미리 패턴 하나 생성 21 | ptns = [ 22 | ['BWBWBWBW', 'WBWBWBWB'] * 4, 23 | ['WBWBWBWB', 'BWBWBWBW'] * 4, 24 | ] 25 | res = N * M 26 | for i in range(N - 7): #2X5로 추산해야하기 때문에 -7한다 (for값은 +1이 최대값)ss 27 | for j in range(M - 7): 28 | for ptn in ptns: 29 | cnt = 0 30 | for di in range(8): 31 | for dj in range(8): 32 | if board[i + di][j + dj] != ptn[di][dj]: 33 | cnt += 1 34 | res = min(res, cnt) 35 | print(res) 36 | 37 | -------------------------------------------------------------------------------- /kws0315/week-1/BaekJoon-2309.py: -------------------------------------------------------------------------------- 1 | from math import * 2 | from heapq import heappop, heappush 3 | from itertools import combinations 4 | from collections import defaultdict, deque 5 | from bisect import bisect_left, bisect_right 6 | from sys import stdin, setrecursionlimit 7 | from functools import reduce 8 | 9 | input = stdin.readline 10 | setrecursionlimit(10 ** 6) 11 | 12 | INF = int(1e10) 13 | 14 | #백준 2309번 문제: 일곱 난쟁이 15 | if __name__ == '__main__': 16 | #Input 17 | #print("입력값") 18 | num = [int(input()) for _ in range(9)] 19 | 20 | #정렬 및 합계 21 | num.sort() 22 | print(*num) 23 | num_sum = sum(num) 24 | print(num_sum) 25 | 26 | #Output 27 | #print("\n출력값")ss 28 | for i in range(9): 29 | for j in range(i + 1, 9): 30 | if num_sum - num[i] - num[j] == 100: 31 | for k in range(9): 32 | if k != i and k != j: 33 | print(num[k]) 34 | 35 | -------------------------------------------------------------------------------- /kws0315/week-2/BaeckJoon-11047.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | #백준 11047번: 동전 0 6 | if __name__ == '__main__': 7 | #Init 8 | res = [] 9 | 10 | #Input 11 | N, K = map(int, input().split()) 12 | 13 | # Solved 14 | coins = sorted([int(input()) for _ in range(N)], reverse=True) 15 | 16 | cnt = 0 17 | for coin in coins: 18 | if K >= coin: 19 | cnt += K // coin 20 | K %= coin 21 | 22 | # Output 23 | print(cnt) -------------------------------------------------------------------------------- /kws0315/week-2/BaeckJoon-17478.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | def generate_msg(cnt, idx): 6 | return "____" * cnt + msg_list[idx] 7 | 8 | def recursive(depth): 9 | if depth == 0: 10 | print("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.") 11 | elif depth <= N: 12 | for i in range(4): 13 | print(generate_msg(depth - 1, i)) 14 | elif depth == N + 1: 15 | for i in range(4, 7): 16 | print(generate_msg(depth - 1, i)) 17 | return 18 | recursive(depth + 1) 19 | if depth >= 1: 20 | print(generate_msg(depth - 1, 6)) 21 | 22 | 23 | #백준 17478번: 재귀함수가 뭔가요? 24 | if __name__ == '__main__': 25 | N = int(input()) 26 | msg_list = [ 27 | "\"재귀함수가 뭔가요?\"" 28 | "\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.", 29 | "마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.", 30 | "그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\"", 31 | 32 | "\"재귀함수가 뭔가요?\"", 33 | "\"재귀함수는 자기 자신을 호출하는 함수라네\"", 34 | 35 | "라고 답변하였지." 36 | ] 37 | 38 | for i in range(N): 39 | recursive(i) 40 | 41 | 42 | -------------------------------------------------------------------------------- /kws0315/week-2/BaeckJoon-19564.py: -------------------------------------------------------------------------------- 1 | from math import * 2 | from heapq import heappop, heappush 3 | from itertools import combinations 4 | from collections import defaultdict, deque 5 | from bisect import bisect_left, bisect_right 6 | from sys import stdin, setrecursionlimit 7 | 8 | input = stdin.readline 9 | setrecursionlimit(10 ** 6) 10 | 11 | INF = int(1e10) 12 | 13 | #백준 19564번: 반복 14 | if __name__ == '__main__': 15 | S = input().rstrip() 16 | L = 1 17 | for i in range(1, len(S)): 18 | if S[i] <= S[i-1]: #Python에선 아스키코드를 숫자로 바로 볼 수 있음 19 | L += 1 20 | print(L) 21 | -------------------------------------------------------------------------------- /kws0315/week-2/BaeckJoon-2217.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | #백준 2217번: 로프 6 | if __name__ == '__main__': 7 | N = int(input()) 8 | 9 | rope_list = sorted([int(input()) for _ in range(N)], reverse=True) 10 | for idx, rope in enumerate(rope_list): 11 | res = max(res, rope * (idx + 1)) 12 | 13 | # Output 14 | print(res) 15 | -------------------------------------------------------------------------------- /kws0315/week-2/BaekJoon-2960.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | N, K = map(int, input().split()) 3 | Nums = [n for n in range(N)] 4 | 5 | # Solve 6 | is_prime = [True] * (N + 1) 7 | for i in range(2, N + 1): 8 | for j in range(i, N + 1, i): 9 | if is_prime[j]: 10 | is_prime[j] = False 11 | if (K := K - 1) == 0: 12 | # Output 13 | print(j) 14 | exit(0) 15 | 16 | 17 | -------------------------------------------------------------------------------- /kws0315/week-3/BaekJoon-10816.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | input = stdin.readline 3 | from bisect import bisect_left, bisect_right 4 | 5 | #백준 10816번: 숫자 카드 2 6 | if __name__ == '__main__': 7 | res = [] 8 | N = int(input()) 9 | A = [*map(int, input().split())] 10 | M = int(input()) 11 | B = [*map(int, input().split())] 12 | 13 | cnt = [0] * M 14 | A.sort() 15 | for idx, target in enumerate(B): 16 | cnt[idx] = bisect_right(A, target) - bisect_left(A, target) 17 | 18 | print(*cnt) 19 | 20 | -------------------------------------------------------------------------------- /kws0315/week-3/BaekJoon-1654.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | input = stdin.readline 3 | 4 | def binary_search(arr): 5 | left, right = 1, max(arr) 6 | res = 0 7 | while left <= right: 8 | mid = (left + right) // 2 9 | cnt = sum([cable // mid for cable in arr]) 10 | if cnt >= N: 11 | res = max(res, mid) 12 | left = mid + 1 13 | else: 14 | right = mid - 1 15 | return res 16 | 17 | if __name__ == '__main__': 18 | # Input 19 | K, N = map(int, input().split()) 20 | cable_list = [int(input()) for _ in range(K)] 21 | 22 | # Solve & Output 23 | print(binary_search(cable_list)) 24 | -------------------------------------------------------------------------------- /kws0315/week-3/BaekJoon-1920.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | input = stdin.readline 4 | 5 | def binary_search(arr, target): 6 | left, right = 0, len(arr) - 1 7 | 8 | while left <= right: 9 | mid = (left + right) // 2 10 | if arr[mid] == target: 11 | return 1 12 | elif arr[mid] < target: 13 | left = mid + 1 14 | else: 15 | right = mid - 1 16 | return 0 17 | 18 | #백준 1920번: 수 찾기 19 | if __name__ == '__main__': 20 | n = int(input()) 21 | A = sorted([*map(int, input().split())]) 22 | m = int(input()) 23 | B = list(map(int, input().split())) 24 | 25 | for target in B: #여러번 출력하기 떄문에 시간 부족이 일어날 수 있음 26 | #프로그래머스같은 사이트에선 이렇게 하지 말고 리스트에 넣어서 한번에 출력하기 27 | print(binary_search(A, target)) 28 | 29 | -------------------------------------------------------------------------------- /kws0315/week-3/BaekJoon-2609.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from math import gcd 3 | input = stdin.readline 4 | 5 | if __name__ == '__main__': 6 | n1, n2 = map(int, input().split()) 7 | 8 | gcd = gcd(n1, n2) 9 | lcm = (n1*n2) // gcd 10 | 11 | print(gcd) 12 | print(lcm) -------------------------------------------------------------------------------- /kws0315/week-3/BaekJoon-9613.py: -------------------------------------------------------------------------------- 1 | from math import * 2 | from sys import stdin 3 | 4 | input = stdin.readline 5 | 6 | if __name__ == '__main__': 7 | for _ in range(int(input())): 8 | # Input 9 | N, *A = [*map(int, input().rstrip().split())] 10 | 11 | # Solve 12 | gcd_sum = 0 13 | for i in range(N - 1): 14 | for j in range(i + 1, N): 15 | gcd_sum += gcd(A[i], A[j]) 16 | 17 | # Output 18 | print(gcd_sum) -------------------------------------------------------------------------------- /mhe1239/week-6/2910.py: -------------------------------------------------------------------------------- 1 | """ 2 | b3 2910, 빈도 정렬 3 | n: 길이 n 4 | C: output은 모두 c보다 작거나 같다. 5 | output: 얼마나 나왔느냐에 따라 input갯수 6 | """ 7 | 8 | from collections import Counter 9 | n,c=map(int,input().split()) 10 | A=[*map(int,input().split())] 11 | ch=dict() 12 | for i,v in enumerate(A): 13 | if v not in ch: 14 | ch[v]=i 15 | cnt=Counter(A) 16 | res=sorted(A,key=lambda n:(-cnt[n],ch[n])) 17 | print(*res) 18 | -------------------------------------------------------------------------------- /mhe1239/week-7/11727.py: -------------------------------------------------------------------------------- 1 | # s3 11727, 2xn 타일링 2 2 | """ 3 | 2*i크기의 보드를 채우는 경우의 수 4 | 2*4는 2*3에 2*1 타일 1개 추가 >| 5 | 6 | 2*4는 2*2에 1*2 타일 2개 추가 > || 7 | 2*4는 2*2에 2*2 타일 1개 추가 >[] >>정사각형 타일 8 | 9 | dpi-1에 2x1타일 추가 10 | dpi-2 1x2타일 2개 추가 11 | dpi-2 2x2타일 1개 추가 12 | """ 13 | n=int(input()) 14 | MOD=10_007 15 | dp=[0]*(n+1) 16 | if n==1: 17 | print(n) 18 | elif n==2: 19 | print(3) 20 | else: 21 | dp[1]=1;dp[2]=3 22 | for i in range(3,n+1): 23 | dp[i]=(dp[i-1]+2*dp[i-2])%MOD 24 | print(dp[n]) 25 | -------------------------------------------------------------------------------- /mhe1239/week-7/15988.py: -------------------------------------------------------------------------------- 1 | """ 2 | 1. 문제 정의 : 무엇을 구해야 하는가? 3 | n까지 1,2,3의 합으로 나타내는 경우의 수 4 | 1,2,3의 합으로 n을 만드는 방법의 수 5 | 2. 상태 정의 : dp[i]가 무엇을 의미하는가? 6 | i상태일때 1,2,3의 합의 경우의 수 7 | i-1 i에서 1을 더하기 전 8 | i-2 i에서 2을 더하기 전 9 | i-3 i에서 3을 더하기 전 10 | dp[i]는 정수 i를 1,2,3의 합으로 나타내는 경우의 수 11 | 3. 점화식 설계 : 다음 상태를 만들기 위해 어떠한 이전 상태가 필요한가? 12 | 현재 수가 나오는 1,2,3들의 합 13 | → **“기존에 저장한 값을 어떻게 재활용 하는가?”** 14 | 4. 초기값 설정 : 가장 작은 상태는 무엇을 의미하며 값은 몇인가? 15 | 경우의 수 16 | 17 | 5. 코드 구현 18 | 19 | """ 20 | 21 | from sys import stdin 22 | input=stdin.readline 23 | t=int(input()) 24 | MOD=1_000_000_009 25 | dp=[0]*1_000_001 26 | dp[1]=1;dp[2]=2;dp[3]=4 27 | for i in range(4,1_000_001): 28 | dp[i]=(dp[i-1]+dp[i-2]+dp[i-3])%MOD 29 | for _ in range(t): 30 | n=int(input()) 31 | print(dp[n]) 32 | -------------------------------------------------------------------------------- /mhe1239/week-8/2565.py: -------------------------------------------------------------------------------- 1 | n=int(input()) 2 | lsit=[[*map(int,input().split())] for _ in range(n)] 3 | lsit.sort() 4 | b=[_[1] for _ in lsit] 5 | dp=[1]*n 6 | for i in range(n): 7 | for j in range(i): 8 | if b[j]