24h購物| | PChome| 登入
2011-12-14 23:05:22| 人氣1,387| 回應0 | 上一篇 | 下一篇

[UVA] 10177 - (2/3/4)-D Sqr/Rects/Cubes/Boxes?

推薦 0 收藏 0 轉貼0 訂閱站台

Problem J

(2/3/4)-DSqr/Rects/Cubes/Boxes?

Input: standard input

Output: standardoutput

Time Limit:2 seconds

 

You can see a (4x4) grid below.Can you tell me how many squares and rectangles are hidden there? You can assumethat squares are not rectangles. Perhaps one can count it by hand but can youcount it for a (100x100) grid or a (10000x10000) grid. Can you do it for higherdimensions? That is can you count how many cubes or boxes of different size arethere in a (10x10x10) sized cube or how many hyper-cubes or hyper-boxes ofdifferent size are there in a four-dimensional (5x5x5x5) sized hypercube.Remember that your program needs to be very efficient. You can assume thatsquares are not rectangles, cubes are not boxes and hyper-cubes are nothyper-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 cubeor hypercube. As for the example above the value of N is 4. There may be asmany 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 dimensionsas 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



#include<stdio.h>
int main() {
    long long n;
    while(scanf("%lld", &n) == 1) {
        long long a, b, c, d, e = 0, f, i;
        a = n*(n+1)*(2*n+1)/6;
        b = (n+1)*n/2*(n+1)*n/2 - a;
        c = n*(n+1)/2*n*(n+1)/2;
        d = (n+1)*n/2*(n+1)*n/2*(n+1)*n/2 - c;
        for(i = 1; i <= n; i++)    e += i*i*i*i;
        f = (n+1)*n/2*(n+1)*n/2*(n+1)*n/2*(n+1)*n/2 - e;
        printf("%lld %lld %lld %lld %lld %lld\n", a, b, c, d, e, f);
    }
    return 0;
}

台長: Morris
人氣(1,387) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 11732 - strcmp() Anyone?
此分類上一篇:[UVA] 11332 - Summing Digits

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文