/* BirdBath */ #define DEBUG (1 == 1) #include <stdio.h> #define SIZE 6 #define STATUEMAX 6 int main() { // main int numPuzzles; // number of puzzles to solve int board[SIZE][SIZE]; // yard matrix int bbRow; // start row for BirdBath int bbCol; // start column for BirdBath int numStatues; // number of Statues int numPushes; // number of bb pushes for this puzzle int dir; // direction being pushed int np; // loop control variable (loops through puzzles) int p; // loop control variable (loops through pushes) int i,j; // loop control variables int r; // row int c; // column int OnBoard; // flag to see if we are still on board scanf(" %d", &numPuzzles); if (DEBUG) printf("Number of puzzles: %d\n", numPuzzles); for (np=0; np < numPuzzles; np++) { // loop for each puzzle // load the row and column of where BB starts scanf(" %d %d", &bbRow, &bbCol); if (DEBUG) printf("BirdBath starts: [%d,%d]\n", bbRow, bbCol); scanf(" %d", &numStatues); if (DEBUG) printf("Number of statues: %d\n", numStatues); // test to make sure num statues is valid // empty board for (i=1; i < SIZE; i++) for (j=1; j < SIZE; j++) board[i][j] = 0; // mark the board with statue locations for (i=0; i < numStatues; i++) { // load statue locations scanf(" %d %d", &r, &c); if (DEBUG) printf("Statue location: [%d,%d]\n",r,c); board[r][c] = 1; } // load statue locations // load the number of pushes scanf(" %d", &numPushes); if (DEBUG) printf("Number of pushes: %d\n", numPushes); r = bbRow; c = bbCol; OnBoard = ((r > 0) && (r < SIZE) && (c > 0) && (c < SIZE)); for (p=0; p < numPushes; p++) { // push statue scanf(" %d", &dir); if (DEBUG) printf("Direction: %d\n", dir); if (OnBoard) { // Still on the board switch (dir) { // switch case 8: r = r + 1; while ((r < SIZE) && (board[r][c] == 0)) { // while if (DEBUG) printf("Checking: [%d,%d]\n", r, c); r = r + 1; } // while OnBoard = (r < SIZE); r = r - 1; break; case 2: r = r - 1; while ((r > 0) && (board[r][c] == 0)) { // while if (DEBUG) printf("Checking: [%d,%d]\n", r, c); r = r - 1; } // while OnBoard = (r > 0); r = r + 1; break; case 6: c = c + 1; while ((c < SIZE) && (board[r][c] == 0)) { // while if (DEBUG) printf("Checking: [%d,%d]\n", r, c); c = c + 1; } // while OnBoard = (c < SIZE); c = c - 1; break; case 4: c = c - 1; while ((c > 0) && (board[r][c] == 0)) { // while if (DEBUG) printf("Checking: [%d,%d]\n", r, c); c = c - 1; } // while OnBoard = (c > 0); c = c + 1; break; } // switch } // Still on the board } // push statue if (OnBoard) { // BB still on board if ((r == 3) && (c == 3)) { // in center printf("BIRDBATH IN YOUR YARD\n"); } // in center else { // not in center printf("BIRDBATH IN THE WAY\n"); } // not in center } // BB still on board else { // BB hit fence printf("BIRDBATH IN THE FENCE\n"); } // BB hit fence } // loop for each puzzle } // main Return to Problem Index |