Poj 1656 counting Black (simulation)

Source: Internet
Author: User
Counting black
Time limit:1000 ms   Memory limit:10000 K
Total submissions:9101   Accepted:5879

Description

There is a board with 100*100 grids as shown below. The left-top gird is denoted as (1, 1) and the right-bottom grid is (100,100 ).


We may apply three commands to the Board:

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)

In the beginning, all the grids on the board are white. we apply
Series of commands to the board. Your task is to write a program to give
The numbers of black grids within a required region when a test command
Is applied.

Input

The
First line of the input is an integer T (1 <= T <= 100 ),
Representing the number of commands. In each of the following lines,
There is a command. Assume all the commands are legal which means that
They won't try to paint/test the grids outside the board.

Output

For each test command, print a line with the number of black grids in the required region.

Sample Input

 
5 black 1 1 2 black 2 2 2 Test 1 1 3 white 2 1 1 Test 1 3

Sample output

 
76
# Include <iostream> # Define Maxnum101 Using   Namespace  STD; Int Point [maxnum] [maxnum]; //  Mark grid color  Int  Main (){  Int T; //  T Cases  //  (X y) upper left coordinate (x1, Y1) lower right coordinate num: number of records black      Int  X, Y, X1, Y1, L, num;  String S; //  Command cmd Cin> T;//  Command count      While (T -- ) {Num = 0  ; CIN > S> x> Y> L; X1 = X + L- 1  ; Y1 = Y + L- 1  ;  //  Black command, set the block in the area to Black: 1          If (S. Compare ("  Black  " ) = 0  ){  For ( Int I = x; I <= x1; ++ I)  For ( Int J = y; j <= Y1; ++ J) {point [I] [J] = 1  ;}}  // White command, set the block in the area to White: 0          Else   If (S. Compare ( "  White  " ) = 0  ){  For ( Int I = x; I <= x1; ++ I)  For ( Int J = y; j <= Y1; ++ J) {point [I] [J] = 0  ;}}  //  Test command to output the number of Black Blocks          Else   If (S. Compare ( "  Test  " ) = 0  ){  For ( Int I = x; I <= x1; ++ I)  For (Int J = y; j <= Y1; ++ J ){  If (Point [I] [J] = 1 ) Num ++ ;} Cout <Num < Endl ;}}  Return   0  ;} 

 

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.