uva-10267 - Graphical Editor

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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值