ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Cap Size - 17659
    Algorithm/BOJ 2020. 2. 28. 18:55
    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
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    //17659 - cap size
     
    #include <iostream>
    using namespace std;
     
    int N, K;
    bool arr[1001];
    int lower, upper;
    int obv;
     
    void init()
    {
        cin >> N >> K;
        obv = -1
        for (int i = 0; i < 1001++i)
            arr[i] = false;
        int x;
        for (int i = 0; i < N; ++i)
        {
            cin >> x;
            arr[x] = true;
        }
        lower = -1;
        upper = 100000;
    }
     
    void solve(int C)
    {
        int x, y;
        int flag = true;
        for (int i = 0; i < K; ++i)
        {
            cin >> x >> y;
            if (flag)
            {
                if (y == 1)
                {
                    if (upper <= x)
                    {
                        flag = false;
                        continue;
                    }
                    if (lower < x)
                        lower = x;
                }
                else if (y == -1)
                {
                    if (lower >= x)
                    {
                        flag = false;
                        continue;
                    }
                    if (upper > x)
                        upper = x;
                }
                else
                {
                    if (obv == -1 && x > lower && x < upper)
                        obv = x;
                    else if (obv == x)
                        obv = x;
                    else
                    {
                        flag = false;
                        continue;
                    }
                }
            }
        }
        cout << "Data Set " << C << ":\n";
        if (!flag)
        {
            cout << "Inconsistent feedback\n\n";
            return;
        }
        int ans = 0;
        if (obv != -1)
            if (obv > lower && obv < upper)
            {
                cout << 1 << "\n\n";
                return;
            }
            else
            {
                cout << "Inconsistent feedback\n\n";
                return;
            }
        for (int i = lower + 1; i < upper; ++i)
            if (arr[i])
                ++ans;
     
        cout << ans << "\n\n";
    }
     
    int main()
    {
        int C;
        cin >> C;
        for (int tn = 0; tn < C; ++tn)
        {
            init();
            solve(tn + 1);
        }
    }
    cs

     

     

     

     

     

     

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

     

    17659번: Cap Size

    Picking the right size of your cap is surprisingly difficult. If your cap is too small, it keeps digging into your head, or — even worse — you can’t even get it over your computer science filled head. And if it is too large, it keeps wiggling, and you know

    www.acmicpc.net

     

     

     

     

     

     

    Cap Size

    예외처리만 잘 해주면 되는 문제 입니다.

     

     

     

     

     

     

    'Algorithm > BOJ' 카테고리의 다른 글

    동전 1 - 2293  (0) 2020.03.01
    GPA - 17662  (0) 2020.02.28
    Mangling Names - 17661  (0) 2020.02.28
    계단 수 - 1562  (0) 2020.02.26
    10844 - 쉬운 계단 수  (0) 2020.02.26

    댓글

Designed by Tistory.