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 handle the condition. however , WA……I checked my roblem many 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[265][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 %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 %d %c",&x,&y,&color);
getchar();
ch[x][y]=color;
break;
case 'V':
scanf("%d %d %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 %d %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 %d %d %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 %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;
}