-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10813_Traditional_BINGO.cpp
83 lines (80 loc) · 1.86 KB
/
10813_Traditional_BINGO.cpp
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
#include<iostream>
#include<unordered_map>
using namespace std;
struct rc{
int r;
int c;
};
bool win(bool (&b)[5][5]){
for(int i = 0, j = 0; i < 5 ; i++,j++){
if(b[i][j]){
if(i == 4) return true;
}
else break;
}
for(int i = 4, j = 0; i >= 0 && j < 5 ; i--,j++){
if(b[i][j]){
if(i == 0) return true;
}
else break;
}
for(int i = 0; i < 5; i++){
if(b[0][i]){
for(int j = 1; j < 5; j++){
if(b[j][i]){
if(j == 4) return true;
}
else break;
}
}
}
for(int i = 0; i < 5; i++){
if(b[i][0]){
for(int j = 1; j < 5; j++){
if(b[i][j]){
if(j == 4) return true;
}
else break;
}
}
}
return false;
}
int main()
{
int test;
cin >> test;
while(test--){
unordered_map<int,rc> cord;
bool exist[76] = {};
int card[5][5];
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5; j++){
if(i == 2 && j == 2) continue;
else{
cin >> card[i][j];
cord[card[i][j]] = rc{i,j};
exist[card[i][j]] = true;
}
}
}
bool bingo = false;
bool mark[5][5] = {};
mark[2][2] = true;
for(int i = 0; i < 75; i++){
int x;
cin >> x;
if(!bingo){
if(exist[x]){
auto c = cord[x];
mark[c.r][c.c] = true;
}
if(win(mark)){
bingo = true;
cout << "BINGO after "<<i+1<<" numbers announced\n";
}
}
}
}
return 0;
}