10177-(2/3/4)-D sqr/rects/cubes/boxes?
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem &problem=1118
You can have a (4x4) grid below. Can tell me how many squares and rectangles are hidden there? You can assume this squares are not rectangles. Perhaps one can count it by hand but can your count it for a (100x100) grid or a (10000x10000) grid. Can you does it for higher dimensions? This is can, count how many cubes or boxes the different size are there in a (10x10x10) sized the cube or how many Hyper-cub Es or hyper-boxes of different size are there in a four-dimensional (5x5x5x5) sized hypercube. Remember that your the needs to be very efficient. You can assume this squares are not rectangles, cubes are not boxes and hyper-cubes not are.
|
|
FIG:A 4x4 Grid |
Fig:a 4x4x4 Cube |
Input
The input contains one integer N (0<=n<=100) in each line, which is the length of one side of the grid or C Ube or hypercube. As for the example above the value of N is 4. There May is as many as lines of input.
Output
For each line of input, output six integers S2, R2, S3, R3, S4, R4 in a single line where S2 means no of Squares of different size in (NxN) two-dimensional grid, R2 means no of rectangles of different size I n (NxN) two-dimensional grid. S3, R3, S4, R4 means similar cases in higher dimensions as described before.
Sample Input:
1
2
3
Sample Output:
1 0 1 0 1 0
5 4 9 18 17 64
14 22 36 180 98 1198
Ideas:
Take two-dimensional as an example, how does the number of squares count?
1x1 must have NXN, the 2x2 is (n-1) * (n-1) ... NXN only 1, is the square and formula.
The same three-dimensional is cubic and formula, four-dimensional is 4 power sum.
Then we ask for the number of rectangles containing squares, minus the number of squares to find out the number of square rectangles, how to ask?
We can think of it this way: Each side takes two lines, and the two lines can make a rectangle (of course, it can be a square, and a square is a rectangle).