#include #define CHESS_BOARD_SIZE 20010 unsigned short int chessboard[CHESS_BOARD_SIZE][CHESS_BOARD_SIZE]; void nullArray(int x, int y){ int i, j; for (j = 1; j <= y; j++) { chessboard[0][j] = x; } for (i = 1; i <= x; i++) { for (j = 1; j <= y; j++) { chessboard[i][j] = 0; } } } int freeCapacity(int columns){ int i, suma = 0; for (i = 1; i <= columns; i++) { suma += chessboard[0][i]; } return suma; } int main(int argc, char** argv) { int i, j, x, y, n; int a, b, leftx; scanf("%d %d %d", &x, &y, &n); while (x+y+n > 1) { if (n != 0){ nullArray(x, y); } else { printf("%d\n", x*y); scanf("%d %d %d", &x, &y, &n); continue; } while (n--) { scanf("%d %d", &a, &b); chessboard[0][b] = 0; for (i = 1; i <= x; i++) { if (chessboard[i][b] == 0) { chessboard[i][0]--; chessboard[i][b] = 1; } } chessboard[a][0] = 0; for (i = 1; i <= y; i++) { if (chessboard[a][i] == 0) { chessboard[0][i]--; chessboard[a][i] = 1; } } leftx = (a < b) ? a : b; for (i = a-leftx+1, j = b-leftx+1; i <= x && j <= y; i++, j++) { if (chessboard[0][j] > 0 && chessboard[i][j] == 0) { chessboard[i][j] = 1; chessboard[0][j]--; } } leftx = (a < b) ? b : a; for (i = a-leftx+1, j = b+leftx-1; i <= x && j > 0; i++, j--) { if (chessboard[0][j] > 0 && chessboard[i][j] == 0) { chessboard[i][j] = 1; chessboard[0][j]--; } } } for (i = 0; i <= x; i++) { for (j = 1; j <= y; j++) { printf("%d ", chessboard[i][j]); } printf("\n"); } printf("%d\n", freeCapacity(y)); scanf("%d %d %d", &x, &y, &n); } return 0; }