4gats 2023. 9. 12. 20:02

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

 

17281번: ⚾

⚾는 9명으로 이루어진 두 팀이 공격과 수비를 번갈아 하는 게임이다. 하나의 이닝은 공격과 수비로 이루어져 있고, 총 N이닝 동안 게임을 진행해야 한다. 한 이닝에 3아웃이 발생하면 이닝이 종

www.acmicpc.net

 

https://www.youtube.com/watch?v=IUKjKaQ8fDI&ab_channel=MintaekOH 

해냈다 해냈어!!

브루트포스 순열 문제이다

do - while문과 next_permutation을 쓰자.

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
 
using namespace std;
 
int ans = 0;
int how[55][10];
int bba[9];
bool base[4];
 
pair<int,int> playball(int inn, int bun)
{
    int score = 0;
    int out_cnt = 0;
    
    memset(base, falsesizeof(base));
 
    while (out_cnt < 3)
    {
        int what = how[inn][bba[bun]];
 
        if (what == 0)
        {
            out_cnt++;
        }
        else if (what == 1)
        {
            for (int i = 3; i >= 1; i--)
            {
                if (i == 3 && base[i])
                {
                    base[i] = false;
                    score++;
                }
                else if (base[i])
                {
                    base[i + 1= true;
                    base[i] = false;
                }
            }
 
            
            base[1= true;
        }
        else if (what == 2)
        {
            for (int i = 2; i <= 3; i++)
            {
                if (base[i])
                {
                    base[i] = false;
                    score += 1;
                }
            }
 
            if (base[1])
            {
                base[1= false;
                base[3= true;
            }
 
            base[2= true;
        }
        else if (what == 3)
        {
            for (int i = 1; i <= 3; i++)
            {
                if (base[i])
                {
                    base[i] = false;
                    score += 1;
                }
            }
            base[3= true;
        }
        else if(what == 4)
        {
            for (int i = 1; i <= 3; i++)
            {
                if (base[i])
                {
                    base[i] = false;
                    score += 1;
                }
            }
            score += 1;
        }
 
        if (bun == 8)
            bun = 0;
        else
            bun++;    
    }
 
    return make_pair(score, bun);
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    vector<int> seq{ 2,3,4,5,6,7,8,9 };
    
    int inning;
    cin >> inning;
 
    for (int i = 0; i < inning; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            cin >> how[i][j];
        }
    }
 
    do
    {
        for (int i = 0; i < 9; i++)
        {
            if (i < 3)
                bba[i] = seq[i];
            else if (i == 3)
                bba[i] = 1;
            else
                bba[i] = seq[i - 1];
        }
 
        
 
        int tmp_score = 0;
        pair<intint> inning_result;
        int cheoum = 0;
 
        for (int i = 0; i < inning; i++)
        {
            inning_result = playball(i, cheoum);
            tmp_score += inning_result.first;
            cheoum = inning_result.second;
        }
 
        ans = max(ans, tmp_score);
 
    } while (next_permutation(seq.begin(), seq.end()));
 
    cout << ans << '\n';
    
    return 0;
}
cs