멋사/TIL

230714 14주 1일차 TIL. Moo 게임 Boj 5904, 데이터베이스 정규화

yeooniyeoon 2023. 7. 17. 18:04
728x90
SMALL

Moo 게임 boj 5904

https://www.acmicpc.net/problem/5904

 

5904번: Moo 게임

Moo는 술자리에서 즐겁게 할 수 있는 게임이다. 이 게임은 Moo수열을 각 사람이 하나씩 순서대로 외치면 되는 게임이다. Moo 수열은 길이가 무한대이며, 다음과 같이 생겼다.  m o o m o o o m o o m o o o

www.acmicpc.net

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Boj5904 {
    public char solution() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());

        int length = 3;

        int reps = 0;

        while (length < n) {
            reps++;
            length = length * 2 + (reps + 3);
            System.out.println(length);
        }
        
        n--;
        while (true) {
            int midIndex = (length - (reps - 3)) / 2;
            int lastIndex = (length - (reps + 3)) / 2 + (reps + 3);
            if (n == midIndex) return 'm';
            else if (midIndex < n && n < lastIndex) return 'o';
            else if (n > lastIndex) {
                n -= lastIndex;
                length -= lastIndex;
            } else {
                length -= reps + 3;
                length -= midIndex;
            }
            reps--;
        }
    }

    public static void main(String[] args) throws IOException {
        System.out.println(new Boj5904().solution());
    }
}

 

 

 

 

데이터베이스 정규화

제 1 정규형

하나의 컬럼이 복수의 데이터를 가지고 있지 않아야 한다.

 

제 2 정규형 

기본키에 종속되지 않는 컬럼은 테이블에서 분리되어야 한다.

 

제 3 정규형

기본키가 아닌 다른 컬럼에 종속성을 갖는 컬럼들은 별도로 분리해야 한다.

 

 

 

728x90
반응형
SMALL