Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8499 | Accepted: 5469 |
Description
1. WHITE x, y, L // Paint a white square on the board, // the square is defined by left-top grid (x, y) // and right-bottom grid (x+L-1, y+L-1) 2. BLACK x, y, L // Paint a black square on the board, // the square is defined by left-top grid (x, y) // and right-bottom grid (x+L-1, y+L-1) 3. TEST x, y, L // Ask for the number of black grids // in the square (x, y)- (x+L-1, y+L-1)
Input
Output
Sample Input
5 BLACK 1 1 2 BLACK 2 2 2 TEST 1 1 3 WHITE 2 1 1 TEST 1 1 3
Sample Output
7 6
Source
#include <cstdio> #include <cstdlib> #include <cstring> int count[110][110]; int main(void){ int casenum ,ii; char oprator[10]; int x, y, l; int i, j; int num, value; while (scanf("%d", &casenum) != EOF){ getchar(); memset(count, 0, sizeof(count)); for (ii = 0; ii < casenum; ii++){ scanf("%s%d%d%d", oprator, &x, &y, &l); getchar(); if (!strcmp(oprator, "TEST")){ value = -1; num = 0; } else if (!strcmp(oprator, "WHITE")){ value = 0; } else if (!strcmp(oprator, "BLACK")){ value = 1; } for (i = x; i <= x + l - 1; i++){ for (j = y; j <= y + l - 1; j++){ if (value == -1){ if (count[i][j] == 1){ num ++; } } else{ count[i][j] = value; } } } if (value == -1){ printf("%d\n", num); } } } return 0; }