UVa 10177 (2/3/4)-D Sqr/Rects/Cubes/Boxes? (数学好题)

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 see a (4x4) grid below. Can you tell me how many squares and rectangles are hidden there? You can assume that squares are not rectangles. Perhaps one can count it by hand but can you count it for a (100x100) grid or a (10000x10000) grid. Can you do it for higher dimensions? That is can you count how many cubes or boxes of different size are there in a (10x10x10) sized cube or how many hyper-cubes or hyper-boxes of different size are there in a four-dimensional (5x5x5x5) sized hypercube. Remember that your program needs to be very efficient. You can assume that squares are not rectangles, cubes are not boxes and hyper-cubes are not hyper-boxes.

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 cube or hypercube. As for the example above the value of N is 4. There may be as many as 100 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 in (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

思路:

以二维为例,正方形的个数怎么算?

1×1的肯定有n×n个,2×2的就有(n-1)*(n-1)个。。。。。。。n×n的只有1个,就是平方和公式。

同理三维就是立方和公式,四维就是4次幂和。

然后我们要求出包含正方形的矩形的个数,减去正方形个数就能求出非正方形矩形的个数了,怎么求?

我们可以这样思考:每条边任意取两条线,这两条线一定能组成一个矩形(当然也可能是正方形,正方形也是矩形)。

时间: 2024-12-01 13:40:46

UVa 10177 (2/3/4)-D Sqr/Rects/Cubes/Boxes? (数学好题)的相关文章

UVa 10405:Longest Common Subsequence,最长公共子序列模板题

[链接] http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=1346 [原题] Problem C: Longest Common Subsequence Sequence 1: Sequence 2: Given two sequences of characters, print the length of

ASP常见数学函数 Abs Atn Cos 等详细详解

[名称] Abs [类别] 数学函数 [原形] Abs(number) [参数] 必选的.Number参数是一个任何有效的数值型表达式 [返回值] 同 number 的类型 [异常/错误] 无 [描述] 返回参数number 的绝对值.一个数的绝对值是将正负号去掉以后的值.例如,ABS(-1) 和 ABS(1) 都返回 1.Abs(5.2)=5.2,Abs(-5)=5 [示例] Dim MyNumber MyNumber = Abs(50.3) ' 返回 50.3. MyNumber = Abs

UVa 10023 Square root:高精度及开平方公式

10023 - Square root Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=964 The Problem You are to determinate X by given Y, from expression The Input The first line is the n

UVa 10602

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1543 类型:贪心 原题: Company Macrohard has released it's new version of editor Nottoobad, which can understand a few voice commands.

UVa 10392 Factoring Large Numbers:素因子分解

10392 - Factoring Large Numbers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=1333 One of the central ideas behind much cryptography is that factoring

UVa 10182 Bee Maja:规律&amp;amp;O(1)算法

10182 - Bee Maja Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1123 Maja is a bee. She lives in a bee hive with thousands of other bees. This bee hive c

算法题之UVA 763

Fibinary Numbers The standard interpretation of the binary number 1010 is 8 + 2 = 10. An alternate way to view the sequence ``1010'' is to use Fibonacci numbers as bases instead of powers of two. For this problem, the terms of the Fibonacci sequence

算法题:UVa 11461 Square Numbers (简单数学)

11461 - Square Numbers Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=24 56 A square number is an integer number whose square root is also an integer.

UVa 10183 How Many Fibs? (统计斐波那契数个数&amp;amp;高精度)

10183 - How Many Fibs? Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1124 Recall the definition of the Fibonacci numbers:    f1 := 1    f2 := 2    fn :