CodeForce158B - 택시 태워 보내기

 이 문제는 택시에 사람들을 태워 보낼 것인데 가장 효율이 좋게 보내는
방법을 생각해 내면 된다.

직관적으로 푸는 문제이므로 설명은 필요 없을 것 같다.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.util.Scanner;

public class CodeForce158B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        int count = 0, one = 0, two = 0, three = 0, four = 0;
        String str;
        n = sc.nextInt();
        sc.nextLine();
        str = sc.nextLine();
        String[] groups = str.split(" ");
        for (int i = 0; i < n; i++) {
            switch (Integer.parseInt(groups[i])) {
                case 1:
                    one++;
                    break;
                case 2:
                    two++;
                    break;
                case 3:
                    three++;
                    break;
                case 4:
                    four++;
                    break;
                default:
                    break;
            }
        }


        count += four;

        if (three >= one) {
            one = 0;
        }else {
            one -= three;
        }
        count += three;

        if (two % 2 == 0) {
            count += (two / 2);
        }else {
            count += ((two - 1) / 2);

            if (one > 1) {
                one -= 2;
                count++;
            }else if (one == 1){
                one -= 1;
                count++;
            }else {
                count++;
            }
        }

        int x = one / 4;
        int y = one % 4;

        count += (x);

        if (y > 0) {
            count++;
        }
    }
}

이 블로그의 인기 게시물

웹툰 무료로 볼 수 있는 사이트

BackJoon 1011, Fly me to the alpha centauri, 규칙 찾기 문제

BaekJoon 6591, 이항 쇼다운 조합문제