Volver a la lista de problemas
The Spot Game
141.c
/* 141 - The Spot Game */ #include <stdio.h> #include <string.h> typedef char board[52][52]; int n; board boards[105]; int winner, move; int pat1(int a, int b) { int i,j; for (i=0; i<n; i++) { for (j=0; j<n; j++) { if (boards[a][i][j] != boards[b][i][j]) { return 0; } } } return 1; } int pat2(int a, int b) { int i,j; for (i=0; i<n; i++) { for (j=0; j<n; j++) { if (boards[a][i][j] != boards[b][n-j-1][i]) { return 0; } } } return 1; } int pat3(int a, int b) { int i,j; for (i=0; i<n; i++) { for (j=0; j<n; j++) { if (boards[a][i][j] != boards[b][j][n-i-1]) { return 0; } } } return 1; } int pat4(int a, int b) { int i,j; for (i=0; i<n; i++) { for (j=0; j<n; j++) { if (boards[a][i][j] != boards[b][n-i-1][n-j-1]) { return 0; } } } return 1; } int pattern(int a, int b) { if (pat1(a,b) || pat2(a,b) || pat3(a,b) || pat4(a,b)) { return 1; } return 0; } void play(int i, int a, int b) { int j; if (winner) { return; } memcpy(&boards[i], &boards[i-1], sizeof(board)); boards[i][a-1][b-1] ^= 1; for (j=0; j<i; j++) { if (pattern(i,j)) { winner=1; move=i; } } } int main(void) { while (1) { int i; if (scanf("%d", &n) != 1 || n==0) { break; } memset(boards, 0, sizeof(boards)); winner=0; for (i=0; i<2*n; i++) { int a,b; char c; scanf("%d %d %c", &a, &b, &c); play(i+1,a,b); } if (winner) { printf("Player %d wins on move %d\n", move%2+1, move); } else { printf("Draw\n"); } } return 0; }