I was so careless that I have got about 20 was for this problem. ffffffffffffff ^.
The ananlysis:
This problem is very easy, and it just a simple simulation problem. and the most difficult part in this problem is the F operation. I use depth searching first time, but I got a PE. I knew it is the problem of stackoverflow. so I Chang to use queue, then I got a TLE, I check my solution seriously, and I found a infinity circle. then I judged when the color was same with the old color, do not h Andle The condition. However, wa ...... I checked my roblem timed times, And I Can promised it was right, but it was still wrong. then I wrote a letter thtough the contact us ,. all of a sudden, I found a mistake. the problem requested you use 'O' to init the array. however I used the '0' instead. I was so sorry for my carelessness to waste so much time. I have got this lecture. and write this article to remind me of it all the time.
The code:
# Include <stdio. h>
# Include <string. h>
Int M, N;
Char ch [1, 265] [2, 265];
Char oldcol;
Int queue [6250000] [2];
Void solve (int x, int y, char col)
{
Int base =-1, Top = 0;
Ch [x] [Y] = Col;
Queue [0] [0] = X;
Queue [0] [1] = y;
If (Col! = Oldcol)
{
While (base! = Top)
{
Base ++;
If (queue [base] [0] <= 0 | queue [base] [0]> M | queue [base] [1] <= 0 | queue [base] [1]> N)
Continue;
If (CH [queue [base] [0]-1] [queue [base] [1] = oldcol)
{
Top ++;
Ch [queue [base] [0]-1] [queue [base] [1] = Col;
Queue [Top] [0] = queue [base] [0]-1;
Queue [Top] [1] = queue [base] [1];
}
If (CH [queue [base] [0] + 1] [queue [base] [1] = oldcol)
{
Top ++;
Ch [queue [base] [0] + 1] [queue [base] [1] = Col;
Queue [Top] [0] = queue [base] [0] + 1;
Queue [Top] [1] = queue [base] [1];
}
If (CH [queue [base] [0] [queue [base] [1]-1] = oldcol)
{
Top ++;
Ch [queue [base] [0] [queue [base] [1]-1] = Col;
Queue [Top] [0] = queue [base] [0];
Queue [Top] [1] = queue [base] [1]-1;
}
If (CH [queue [base] [0] [queue [base] [1] + 1] = oldcol)
{
Top ++;
Ch [queue [base] [0] [queue [base] [1] + 1] = Col;
Queue [Top] [0] = queue [base] [0];
Queue [Top] [1] = queue [base] [1] + 1;
}
}
}
}
Int main ()
{
Int I, J, K, X1, Y1, X2, Y2, X, Y;
Char COM, color, name [1050], erro [1050];
Int flag = 1;
Memset (CH,-1, sizeof (CH ));
While (FLAG)
{
Scanf ("% C", & Com );
Switch (COM)
{
Case 'I ':
Scanf ("% d", & M, & N );
Getchar ();
For (I = 1; I <= m; I ++)
For (j = 1; j <= N; j ++)
Ch [I] [J] = 'O ';
Break;
Case 'C ':
Getchar ();
For (I = 1; I <= m; I ++)
For (j = 1; j <= N; j ++)
Ch [I] [J] = 'O ';
Break;
Case 'l ':
Scanf ("% d % C", & X, & Y, & color );
Getchar ();
Ch [x] [Y] = color;
Break;
Case 'V ':
Scanf ("% d % C", & X, & Y1, & Y2, & color );
Getchar ();
If (Y1> Y2)
{
K = Y1; Y1 = Y2; y2 = K;
}
For (I = Y1; I <= Y2; I ++)
Ch [x] [I] = color;
Break;
Case 'H ':
Scanf ("% d % C", & X1, & X2, & Y, & color );
Getchar ();
If (x1> x2)
{
K = x1; X1 = x2; x2 = K;
}
For (I = x1; I <= x2; I ++)
Ch [I] [Y] = color;
Break;
Case 'K ':
Scanf ("% d % C", & X1, & Y1, & X2, & Y2, & color );
Getchar ();
If (x1> x2)
{
K = x1; X1 = x2; x2 = K;
}
If (Y1> Y2)
{
K = Y1; Y1 = Y2; y2 = K;
}
For (I = x1; I <= x2; I ++)
For (j = Y1; j <= Y2; j ++)
Ch [I] [J] = color;
Break;
Case 'F ':
Scanf ("% d % C", & X, & Y, & color );
Getchar ();
Oldcol = CH [x] [Y];
Solve (X, Y, color );
Break;
Case's ':
Getchar ();
Gets (name );
Printf ("% s/n", name );
For (I = 1; I <= N; I ++)
{
For (j = 1; j <= m; j ++)
{
Printf ("% C", CH [J] [I]);
}
Printf ("/N ");
}
Break;
Case 'X ':
Flag = 0;
Break;
Default:
Gets (erro );
Break;
}
}
Return 0;
}