티스토리 뷰
728x90
문제 링크
https://www.acmicpc.net/problem/16722
어렵진 않지만 귀찮은 구현문제이다.
주어진 9개 그림의 모든 조합을 미리 구해놓고 쿼리를 해결하자.
정답 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <tuple> | |
#include <algorithm> | |
#include <string> | |
using namespace std; | |
bool comb[10][10][10], chk[10][10][10]; | |
bool foo(const string &x, const string &xx, const string &xxx) { | |
return (x == xx && xx == xxx) || (x != xx && xx != xxx && xxx != x); | |
} | |
void bar(int &a, int &b, int &c) { | |
int l = min({ a, b, c }); | |
int r = max({ a, b, c }); | |
b = a + b + c - l - r; | |
a = l; | |
c = r; | |
} | |
tuple<string, string, string> p[10]; | |
int main() { | |
ios_base::sync_with_stdio(false); | |
cin.tie(0); | |
for (int i = 1; i < 10; i++) { | |
string x, y, z; | |
cin >> x >> y >> z; | |
p[i] = { x, y, z }; | |
} | |
int kk = 0; | |
for (int i = 1; i < 10; i++) { | |
for (int j = i + 1; j < 10; j++) { | |
for (int k = j + 1; k < 10; k++) { | |
auto[x, y, z] = p[i]; | |
auto[xx, yy, zz] = p[j]; | |
auto[xxx, yyy, zzz] = p[k]; | |
if(comb[i][j][k] = foo(x, xx, xxx) && foo(y, yy, yyy) && foo(z, zz, zzz)) kk++; | |
} | |
} | |
} | |
int n; | |
cin >> n; | |
char c; | |
bool g = false; | |
int ans = 0; | |
while (n--) { | |
cin >> c; | |
if (c == 'H') { | |
int a, b, c; | |
cin >> a >> b >> c; | |
bar(a, b, c); | |
if (!chk[a][b][c] && comb[a][b][c]) { | |
chk[a][b][c] = true; | |
ans++; | |
kk--; | |
} | |
else { | |
ans--; | |
} | |
} | |
else { | |
if (!g && kk == 0) { | |
g = true; | |
ans += 3; | |
} | |
else { | |
ans--; | |
} | |
} | |
} | |
cout << ans; | |
} |
728x90
'알고리즘 > 문제 풀이' 카테고리의 다른 글
[BOJ] 백준 16724 피리 부는 사나이 (1) | 2019.01.20 |
---|---|
[BOJ] 백준 16723 원영이는 ZOAC과 영원하고 싶다 (1) | 2019.01.20 |
[BOJ] 백준 16721 Structure of Balanced Networks (1) | 2019.01.20 |
[BOJ] 백준 16720 BAZE RUNNER (0) | 2019.01.20 |
[BOJ] 백준 16719 ZOAC (2) | 2019.01.20 |