|
|
вернуться в форумPlease help me. I'm really fustrated now :( 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. > 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 > } |
|
|