Competition/codeforces

Codeforces Round #552 (Div. 3) C. Gourmet Cat

shyram 2019. 4. 17. 13:21

C. Gourmet Cat

https://codeforces.com/contest/1154/problem/C


a, b, c를 입력받아 각 수를 3, 2, 2로 나눌때 가장 작은 몫을 선택하자. 어떤 요일을 선택해도 몇 주일을 갈 수 있는가를 나타낸다.

그리고 모든 요일에 대해 며칠을 갈 수 있는지 완전탐색하여 구하자.

완전탐색을 할 때 a, b, c를 직접 변경하는게 아니라, 다른 변수에 할당해서 원본값은 보존해야 한다.

가장 많은 날을 갈 수 있는 요일을 선택하고, 앞에서 구한 몇 주일 * 7과 더해주고 출력하자.


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
#include <bits/stdc++.h>
using namespace std;
 
int a, b, c;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    cin >> a >> b >> c;
 
    int minv = 1e9;
    if (a >= 3 && b >= 2 && c >= 2) {
        minv = min(a / 3, b / 2);
        minv = min(minv, c / 2);
    }
    else {
        minv = 0;
    }
 
    a -= minv * 3;
    b -= minv * 2;
    c -= minv * 2;
 
    string s = "abcacba";
    int maxv = 0;
    int maxi = 0;
 
    for (int i = 0; i < 7; i++) {
        int temp = 0;
        int sa = a, sb = b, sc = c;
        for (int j = 0; j < 7; j++) {
            int cur = (i + j) % 7;
            if (s[cur] == 'a') {
                if (sa == 0break;
                sa--;
                temp++;
            }
            else if (s[cur] == 'b') {
                if (sb == 0break;
                sb--;
                temp++;
            }
            else {
                if (sc == 0break;
                sc--;
                temp++;
            }
        }
        maxv = max(maxv, temp);
    }
 
    cout << minv * 7 + maxv;
 
    return 0;
}
cs