Algorithm/이코테

    완전 탐색 문제 유형(2) - 왕실의 나이트

    # 현재 나이트의 위치 입력 받기 input_data = input() row = int(input_data[1]) # ord : 하나의 문자를 인자로 받아 유니코드 정수를 반환 col = int(ord(input_data[0])) - int(ord('a')) + 1 # 나이트가 이동할 수 있는 8가지 방향 정의 steps = [(-2, -1), (-1, -2), (1, -2), (2, -1), (2, 1), (1, 2), (-1, 2), (-2, 1)] # 8가지 방향에 대하여 각 위치로 이동이 가능한지 확인 count = 0 for step in steps: # 이동하고자 하는 위치 확인 next_row = row + step[0] next_col = col + step[1] # 해당 위치로 이동이 ..

    완전 탐색 문제 유형(1) - 시각

    n = int(input()) count = 0 for i in range(n+1): for j in range(60): for k in range(60): # i, j, k를 하나의 문자열로 합친 후, # 합친 문자열에 3이 포함되어 있으면 true if '3' in str(i) + str(j) + str(k): count += 1 print(count)

    구현 문제 유형(1) - 상하좌우

    # N 입력 받기 N = int(input()) x, y = 1, 1 plans = input().split() # L, R, U, D에 따른 이동 방향 dx = [0, 0, -1, 1] dy = [-1, 1, 0, 0] move_types = ['L', 'R', 'U', 'D'] # 이동 계획을 하나씩 확인하기 for plan in plans: # 이동 후 좌표 구하기 for i in range(len(move_types)): if plan == move_types[i]: nx = x + dx[i] ny = y + dy[i] # 공간을 벗어나는 경우 무시 if nx N or ny > N: continue # 이동 수행 x, y = nx, ny print(x, y)

    그리디 문제 유형(3) - 모험가 길드

    public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int result = 0; // 총 그룹 수 int count = 0; // 현재 그룹에 인원 수 int[] arr = new int[N]; for(int i=0; i

    그리디 문제 유형(2) - 곱하기 혹은 더하기

    public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int temp = 0; for(int i=0; i

    그리디 문제 유형(1) - 1이 될 때까지

    public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); int count = 0; while(N != 1) { if(N % K == 0) { N = N / K; count++; } else { N -= 1; count++; } } System.out.println(count); } }