Algorithm

    구현 문제 유형(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); } }

    알고리즘 성능 평가 - (시간, 공간 복잡도, 빅오 표기법)

    알고리즘 성능 평가 복잡도(Complexity) - 알고리즘의 성능을 나타내는 기준 1. 시간 복잡도 - 알고리즘의 수행시간 분석 - 시간 복잡도가 높을수록, 수행 시간이 오래 걸리고 시간 복잡도가 낮을수록, 수행 시간이 적게 소요된다. 2. 공간 복잡도 - 알고리즘의 메모리사용량 분석 - 공간 복잡도가 높을수록, 메모리를 많이 사용하고 공간 복잡도가 낮을수록, 메모리를 적게 사용한다. 결론 : 복잡도가 낮을수록 좋은 알고리즘 ! 빅오 표기법(Big-O Notation) - 차수가 가장 큰 항을 기준으로 표현 시간 복잡도 순위 (좋은 순위부터 나쁜 순위 순) O(1) : 상수 시간(Constant time) O(logN) : 로그 시간(Log time) O(N) : 선형 시간 O(NlogN) : 로그 선..

    백준 11866 (요세푸스 문제 0)

    import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); // 총 인원 int K = sc.nextInt(); // K번째 사람을 제거 Queue q = new LinkedList(); // 선입선출(FIFO) 자료구조 for(int i=1; i1) { // 맨 뒤에 ", " 대신 ">"를 붙여야 하므로 마지막 요소는 남겨 놓는다. for(int i=0; i

    백준 4344 (평균은 넘겠지)

    1234567891011121314151617181920212223242526272829303132import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int C = scan.nextInt(); // 테스트 케이스의 개수 for (int i=0; i

    백준 10809 (알파벳 찾기)

    12345678910111213141516171819202122232425import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int[] arr = new int[26]; String S = scan.nextLine(); for(int i=0; i