목록Algorithm/BaekJoon Online Judge (14)
Code&Data Insights
2022.01.31 # 1. Stage 9 - [ 3009 ] [3009] - 네번째 점 # 2. Stage 9 - [ 1085 ] [1085] - 직사각형에서 탈출
2022.01.27 # Stage 10 브루트 포스 - [2798] 브루트 포스 알고리즘은 주로 비밀번호를 해킹할 때 쓰이며, 주어진 숫자나 리스트의 모든 경우의 수를 고려해 될때까지 시도해 보는 방식이다. [ 2798 ] - 블랙잭 [ my code ] combinations(리스트, 인자값) combinations()는 리스트 내의 모든 조합을 나타낸다. ++ from itertools import permutations 하나의 리스트에서 모든 순열 from itertools import combinations 하나의 리스트에서 모든 조합 from itertools import product 두개 이상의 리스트에서 모든 조합
2022.01.26 # Stage 8 - [10757] [ 10757 ] - 큰 수 A +B [ my code ] a, b = map(int, input().split()) def add(a,b): return a+b print(add(a,b)) # Stage 8 - [2775] [ 2775 ] - 부녀회장이 될테야 [ my code ] -----> 이런식으로 0층에 i호에는 i명이 살고 0층만 factorial 그 이후에는 1호를 제외한 그후의 호수의 명수를 더해서 출력된다. [ my code - First Attempt ] [ my code - Second Attempt ] --> 마지막에 [-1]을 안해줘서 출력초과가 난것 같다.
2022.01.25 # Stage 8 - [2839] [ 2839 ] - 설탕 배달 [ my code - 1st attempt ] [ my code - 2nd attempt ] ---> 예제는 다 옳게 출력되는데 틀려서 나름 경우의 수를 더 추가해서 했는데 또 틀림.. =====> 일단 if-else 문으로 푸는건 너무 막연하고 내가 입력한 케이스는 너무 적었다. 거의 한시간~2시간 동안 붙잡고 있다가 다른 분들 어떻게 풀었는 지 쭉 봤는데 거의 함수나 whilte문 이용해서 풀어서 나도 그쪽 으로 생각해 보기로 했다. 너무 안풀리면, 앞으로 수학적으로 먼저 알고리즘 정리한 후에 다른 방법을 생각해 보는게 좋을 것 같다. [ 풀이 ] 여기서 3키로와 5키로의 설탕 주머니를 배달할 때, 5나 3으로 딱 떨..
2022.01.22 # 1. Stage 10 - [ 10872 ] [JAVA] import java.util.Scanner; public class Main { public static int Factorial(int a){ if (a == 1) { return 1; }else if(a==0) { return 1; }else { return a *Factorial(a-1); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.println(Factorial(n)); } } ----..
2022.01.21 # Stage 8 - [ 1712] [1712] - 손익분기점 [first code] a,b,c = map(int, input().split()) n = 0 while True: if a + (b*n) == (c*n): print(n+1) break elif b > c: print(-1) break n += 1 ---> 이렇게 하니까 예제 1,2번은 통과인데 마지막 숫자 큰 예제는 아웃풋 안나오고, 백준에서 시간초과가 떴다. [new code] a,b,c = map(int, input().split()) b_e_point = 0 if (b >= c): print(-1) else: b_e_point = (a // (c-b)) + 1 print(b_e_point) ---> 처음에 if(b..
2022.01.20 지금까지 어려웠던 & 틀렸던 문제 다시 풀어보기 [10871] [my code] n,x = map(int, input().split()) arr = [] for i in range(n): i = int(input()) if i 출력은 제대로 됐지만 런타임에러가 났다. [new code] n,x = map(int, input().split()) arr = list(map(int,input().split())) for i in range(n): if arr[i] 시간초과가 떴다. [new code] n = int(input()) num = n cnt = 0 while True: a = num // 10 b = num % 10 c = (a+b)%10 num = (b*10) + c cnt +..
2022.01.17 # 문자열 - stage 7 [2908] [my code] a,b = map(str,input().split()) a_new = int(a[2]+a[1]+a[0]) b_new = int(b[2]+b[1]+b[0]) if a_new > b_new: print(a_new) else: print(b_new) --> if else 대신 list/ join/ reversed 를 써서 max 함수로 풀수있음 ** [::-1] 를 쓰면 문자열을 reverse 시킬 수 있음! [new code] a,b = input().split() a = a[::-1] b = b[::-1] if a > b: print(a) else: print(b) ---------------------------- [5622]..