Poj1548Robots dfs practices
// Search for each row
// Clear all vertices of the row
// Change the position of the last vertex of the row to the next step.
// Then clear all vertices in the following row
// Repeat the preceding operations
# Include
# Include
# Include
Using namespace std;
Const int maxn = 30;
Int line [maxn] [maxn];
Int C, R;
Int ans = 0;
Void dfs (int x, int y)
{
Int pos = y;
For (int j = y; j <= C; j ++)
If (line [x] [j])
{
Line [x] [j] = 0;
Pos = j;
}
If (x = R) return;
Dfs (x + 1, pos );
}
Int main ()
{
Int a, B;
// Freopen ("in.txt", "r", stdin );
While (scanf ("% d", & a, & B) & (! =-1 & B! =-1 ))
{
Memset (line, 0, sizeof (line ));
If (! A &&! B)
{
Printf ("0 \ n ");
Continue;
}
C = R = 0;
While (a & B)
{
C = max (C, B );
R = max (R, );
Line [a] [B] = 1;
Scanf ("% d", & a, & B );
}
Ans = 0;
For (int I = 1; I <= R; I ++)
For (int j = 1; j <= C; j ++)
If (line [I] [j])
{
Dfs (I, j );
Ans ++;
}
Printf ("% d \ n", ans );
}
Return 0;
}