ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1125. Hopscotch

Please help me. I'm really fustrated now :(
Posted by MadPsyentist/Sam 6 Feb 2002 21:36
Why do I get WA?

#include <stdio.h>

const int maxsize=100;
int width, height;
char table[maxsize][maxsize];
int n[maxsize*maxsize*2+1]; // check if the number is square
int s[maxsize]; // precalculated square values

 int a(int n) { // absolute
  if (n<0)
   return -n;
  else
   return n;
 }

void main() {
int i,j,k,l;
int temp;
 // prepare values
 for (i=0; i<=maxsize; i++)
  s[i]=i*i;
 for (i=0; i<=s[maxsize]*2; i++)
  n[i]=0;
 for (i=0; s[i]<=s[maxsize]*2; i++)
  n[s[i]]=1;
 // real process
 scanf("%d%d ",&height,&width);
 for (i=0; i<height; i++)
  for (j=0; j<width; j++)
   scanf(" %c",&(table[i][j]));
 for (i=0; i<height; i++)
  for (j=0; j<width; j++) {
   scanf("%d",&temp);
   if (temp&1)
    for (k=0; k<height; k++)
     for (l=0; l<width; l++)
      if (n[s[a(i-k)] + s[a(j-l)]])
       if (table[k][l]=='W')
        table[k][l]='B';
       else
        table[k][l]='W';
  }
 for (i=0; i<height; i++) {
  for (j=0; j<width; j++)
   printf("%c",table[i][j]);
  printf("\n");
 }
 #ifndef ONLINE_JUDGE
 getchar();getchar();
 #endif
}
Sometimes rewriting works well... I don't know why this program got WA but I got AC with a new one.
Posted by MadPsyentist/Sam 11 Feb 2002 18:21
> Why do I get WA?
>
> #include <stdio.h>
>
> const int maxsize=100;
> int width, height;
> char table[maxsize][maxsize];
> int n[maxsize*maxsize*2+1]; // check if the number is square
> int s[maxsize]; // precalculated square values
>
>  int a(int n) { // absolute
>   if (n<0)
>    return -n;
>   else
>    return n;
>  }
>
> void main() {
> int i,j,k,l;
> int temp;
>  // prepare values
>  for (i=0; i<=maxsize; i++)
>   s[i]=i*i;
>  for (i=0; i<=s[maxsize]*2; i++)
>   n[i]=0;
>  for (i=0; s[i]<=s[maxsize]*2; i++)
>   n[s[i]]=1;
>  // real process
>  scanf("%d%d ",&height,&width);
>  for (i=0; i<height; i++)
>   for (j=0; j<width; j++)
>    scanf(" %c",&(table[i][j]));
>  for (i=0; i<height; i++)
>   for (j=0; j<width; j++) {
>    scanf("%d",&temp);
>    if (temp&1)
>     for (k=0; k<height; k++)
>      for (l=0; l<width; l++)
>       if (n[s[a(i-k)] + s[a(j-l)]])
>        if (table[k][l]=='W')
>         table[k][l]='B';
>        else
>         table[k][l]='W';
>   }
>  for (i=0; i<height; i++) {
>   for (j=0; j<width; j++)
>    printf("%c",table[i][j]);
>   printf("\n");
>  }
>  #ifndef ONLINE_JUDGE
>  getchar();getchar();
>  #endif
> }