D Sqr/Rects/Cubes/Boxes?

Problem J

(2/3/4)-D Sqr/Rects/Cubes/Boxes?

Input: standard input

Output: standard output

Time Limit: 2 seconds

You can see a (4×4) 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 (100×100) grid or a (10000×10000) 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 4×4 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 ofN 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 whereS2 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

#include<stdio.h>int main(){long long s2, r2, s3, r3, s4, r4, n;int i;, &n) != EOF){s2 = n*(n+1)*(2*n+1)/6;for(r2=0,i=n; i>=1; –i)r2 += i*i*(i-1);s3 = s2 + r2;r3 = ((n+1)*n/2-1)*s3;for(s4=0,i=n; i>=1; –i)s4 += i*i*i*i;for(r4=0,i=n; i>=1; –i)r4 += i*(s3+r3-i*i*i);printf(, s2, r2, s3, r3, s4, r4);}return 0;}

解题思路:

四维N*N*N*N的情况和三维的情况差不多:

S4 = n^4 + (n-1)^4 + … … + 1^4

R4 = n*(S3+R3-n^3) + (n-1)*(S3+R3-(n-1)^3) + … … + 1*(R3+S3-1^3);

推了两个小时,香港服务器租用,美国空间,可耻地AC了(1y)

,香港空间停止每日在车水马龙的市井里忙碌的穿梭,

D Sqr/Rects/Cubes/Boxes?

相关文章:

  • 【算法】直接插入排序C语言实现
  • 嵌入式 FAAC1.28 在海思HI3518C/HI3518A平台linux中的编译优化
  • Android 动画animation 深入分析
  • Mybatis极其(最)简(好)单(用)的一个分页插件
  • Ext JS Kitchen Sink [Learning by doing](2)ArrayGrid
  • API开发第三篇:PHP的设计模式之完美的单例模式
  • 使用NGUI时遇到物理引擎错误
  • [redis]redis命令汇总(二)
  • 你感兴趣的文章:

    标签云:

    亚洲高清电影在线, 免费高清电影, 八戒影院夜间, 八戒电影最新大片, 出轨在线电影, 午夜电影院, 在线影院a1166, 在线电影院, 在线观看美剧下载, 日本爱情电影, 日韩高清电影在线, 电影天堂网, 直播盒子app, 聚合直播, 高清美剧, 高清美剧在线观看 EhViewer-E站, E站, E站绿色版, qqmulu.com, qq目录网, qq网站目录,