If a checker has a neighbourhood of the other color than his then I printed his number (and exit); else "Draw"; neighbourhood of (x,y) are: (x+1,y+1) (x+1,y) (x+1,y-1) (x,y+1) (x,y) (x,y-1) (x-1,y+1) (x-1,y) (x-1,y-1) I don't see what's the scope of solving such problems. (except learning english :)) ) still don't understand. Could you explain it more? Edited by author 20.10.2004 17:52 Edited by author 20.10.2004 18:07 According to your statement,I wrote a program and got WA on test 3,could you give me some tests or show me your accpeted code to me? ok this is my code: #include <iostream.h> #include <stdlib.h> int a[10][10]; int free(int x,int y) { if (a[x-1][y-1]==!a[x][y]) return 0; if (a[x-1][y+1]==!a[x][y]) return 0; if (a[x+1][y-1]==!a[x][y]) return 0; if (a[x+1][y+1]==!a[x][y]) return 0; if (a[x+1][y]==!a[x][y]) return 0; if (a[x-1][y]==!a[x][y]) return 0; if (a[x][y+1]==!a[x][y]) return 0; if (a[x][y-1]==!a[x][y]) return 0; return 1; } int main() { char x,y; int xx,yy; int i,j,t; for (i=0;i<10;i++) for (j=0;j<10;j++) a[i][j]=-1; t=0; while (!cin.eof()) { t++; cin>>x>>y; xx=(int)x-(int)'a'+1; yy=(int)y-(int)'1'+1; a[xx][yy]=t%2; if (!free(xx,yy)) { cout<<t<<"\n"; exit(0); } } cout<<"Draw\n"; return 0; } It's a stupid problem anyway but I got really angry solving it so that's why i show you the solution. I'm a Pascaler, so I try my best to understand your C prog. It seems that checkers are not only put in the black cells, but in white cells as well, such as A2, B3 and so on. And also, you mean that a checker can only be felled by a checker belonging to the other player. And you think B1 can fell A1, though in this case B1 will jump off the board! Is the prob statement wrong? program ural1334; var chess:array[0..9,0..9]of boolean; i,x,y:byte; a,b:char; begin for i:=0 to 9 do begin chess[0,i]:=true; chess[9,i]:=true; end; for i:=1 to 8 do begin chess[i,0]:=true; chess[i,9]:=true; end; for i:=1 to 32 do begin readln(a,b); x:=ord(a)-96;y:=ord(b)-48; if (chess[x-1,y-1]<>chess[x+1,y+1]) or (chess[x-1,y+1]<>chess[x+1,y-1]) then begin writeln(i); halt; end; chess[x,y]:=true; end; writeln('Draw'); end. Edited by author 21.10.2004 10:27 I wonder what the problem means. Many thanks if anyone can help #include <iostream> using namespace std; const int n = 8; int LD[2*(n+2)]; // left diagonal int RD[2*(n+2)]; // right diagonal int row[n+1]; // the row int main() { int i; int x,y; char c; memset(LD,0,sizeof LD); memset(RD,0,sizeof RD); memset(row,0,sizeof row); for(i=0;i<32;i++) { cin >> c >> y; x = c-'a'+1; // if(!LD[n-x+y] && !RD[x+y] && !row[y]) { // checks LD[n-x+y] = RD[x+y] = row[y] = 1; } else { cout << i+1 << endl; // one can hit other cin >> c; return 0; } } cout << "Draw" << endl; // is this case possible ? return 0; } Isn`t the problem , only to place some queens , and check whether two of them can hit ? Am I Wrong ? And what is the size of the board ? Thank you . Edited by author 17.10.2004 15:54 может ли шашка рубить назад, рубить с далекой клетки, или останавливаться не сразу за срубаемой шашкой? can u write it in Polish or English ?? |
|