[Cpp]
Description: I can't figure out how to use dynamic rules for this question. Therefore, bfs is used directly.
# Include <cstdio>
# Include <cstring>
Char s [5010] [15];
Int main ()
{
// Freopen ("a.txt", "r", stdin );
Int n, flag;
While (scanf ("% d", & n )! = EOF)
For (int I = 0; I <n; I ++)
{
Scanf ("% s", s [0]);
Flag = 12;
Int last = 1, first = 0;
While (first <last)
{
Int c = 0;
For (int I = 0; I <12; I ++) if (s [first] [I] = 'O') c ++;
If (c <flag) flag = c;
For (int I = 0; I <12; I ++)
{
If (I + 2 <12 & s [first] [I] = 'O' & s [first] [I + 1] = 'O' & s [first] [I + 2] = '-')
{
Strcpy (s [last], s [first]);
S [last] [I] = s [last] [I + 1] = '-';
S [last] [I + 2] = 'O ';
Last ++;
}
If (I-2> = 0 & s [first] [I] = 'O' & s [first] [I-1] = 'O' & s [first] [I-2] = '-')
{
Strcpy (s [last], s [first]);
S [last] [I] = s [last] [I-1] = '-';
S [last] [I-2] = 'O ';
Last ++;
}
}
First ++;
}
Printf ("% d \ n", flag );
}
Return 0;
}
Description: I can't figure out how to use dynamic rules for this question. Therefore, bfs is used directly.
# Include <cstdio>
# Include <cstring>
Char s [5010] [15];
Int main ()
{
// Freopen ("a.txt", "r", stdin );
Int n, flag;
While (scanf ("% d", & n )! = EOF)
For (int I = 0; I <n; I ++)
{
Scanf ("% s", s [0]);
Flag = 12;
Int last = 1, first = 0;
While (first <last)
{
Int c = 0;
For (int I = 0; I <12; I ++) if (s [first] [I] = 'O') c ++;
If (c <flag) flag = c;
For (int I = 0; I <12; I ++)
{
If (I + 2 <12 & s [first] [I] = 'O' & s [first] [I + 1] = 'O' & s [first] [I + 2] = '-')
{
Strcpy (s [last], s [first]);
S [last] [I] = s [last] [I + 1] = '-';
S [last] [I + 2] = 'O ';
Last ++;
}
If (I-2> = 0 & s [first] [I] = 'O' & s [first] [I-1] = 'O' & s [first] [I-2] = '-')
{
Strcpy (s [last], s [first]);
S [last] [I] = s [last] [I-1] = '-';
S [last] [I-2] = 'O ';
Last ++;
}
}
First ++;
}
Printf ("% d \ n", flag );
}
Return 0;
}