[4673] 셀프 넘버
[1. 문제 재정의 및 추상화] d(n) = n + {n 의 각 자리수의 합} ex) d(75) = 75 + 7 + 5 = 87 여기서 n 을 d(n) 의 생성자라 하며, 생성자가 없는 숫자를 셀프 넘버라 한다. ex) 1, 3, 5, 7, 9, ... 요구사항 => 10000보다 작거나 같은 셀프 넘버를 한줄씩 출력해야 함. [2. 해결 계획] 셀프 넘버는 생성자가 없으므로, d(n) 수열에서 가장 처음에 온다 할 수 있다. 계산된 d(n) 은 셀프 넘버가 아니므로, 출력하지 않도록 한다. 10K+1 길이를 갖는 배열을 생성하고, 셀프 넘버인 n 을 index 로 하는 경우 그 값을 0으로하고, 셀프 넘버가 아닌 경우 그 생성자를 저장하도록 한다. [3. 계획 검증] 메모리 제한은 크게 상관 없어 보임..
알고리즘 분석
[1. 문제] 1차원 배열에서 연속된 부분 구간 중 그 합이 최대인 구간을 찾기 ex) [-7, 4, -3, 6, 3, -8, 3, 4] => [4, -3, 6, 3] 이 그 합이 10으로 최대가 됨. [2. 알고리즘에 따른 시간 복잡도] O(N^3) Bruteforce 방식 #include #include #include #include int inefficientMaxSum(const std::vector& input) { const int N = input.size(); int ret = std::numeric_limits::min(); for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { int sum = 0; for (int k = j; k ..
5648. 원자 소멸 시뮬레이션
typedef struct { int y, x, dir, k; }info; static int N; static int board[4096][4096]; static int visit[4096][4096]; static int collision[4096][4096]; static int d[4][2] = { 1, 0, -1, 0, 0, -1, 0, 1 }; static vector vec; static int solution() { int x, y, dir, K, ret = 0; scanf("%d", &N); for (int cnt = 0; cnt < N; cnt++) { scanf("%d %d %d %d", &x, &y, &dir, &K); x += 1000; y += 1000; x *= 2; y *=..