博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA 10177 Sqr/Rects/Cubes/Boxes?
阅读量:6612 次
发布时间:2019-06-24

本文共 2132 字,大约阅读时间需要 7 分钟。

Problem J

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

Input: standard input

Output: standard output

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 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 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 using namespace std;15 int main()16 {17 int n;18 while(scanf("%d",&n)!=EOF)19 {20 long long s2=0, r2=0, s3=0, r3=0, s4=0, r4=0;21 long long m=n*(n+1)/2; 22 for(int i=1;i<=n;i++)23 {24 s2=s2+i*i;25 s3=s3+i*i*i;26 s4=s4+i*i*i*i;27 }28 for(int i=1;i<=n;i++)29 {30 r2=m*m-s2;31 r3=m*m*m-s3;32 r4=m*m*m*m-s4;33 }34 printf("%lld %lld %lld %lld %lld %lld\n",s2,r2,s3,r3,s4,r4);35 }36 return 0;37 }
View Code

转载地址:http://vrxso.baihongyu.com/

你可能感兴趣的文章
xcode - 移动手势
查看>>
细说浏览器特性检测(1)-jQuery1.4添加部分
查看>>
Java基础-算术运算符(Arithmetic Operators)
查看>>
C#编程(四十七)----------集合接口和类型
查看>>
【转】关于大型网站技术演进的思考(十二)--网站静态化处理—缓存(4)
查看>>
积跬步,聚小流------Bootstrap学习记录(1)
查看>>
HDUPhysical Examination(贪心)
查看>>
苹果公司的产品已用完后门与微软垄断,要检查起来,打架!
查看>>
Android官方架构组件LiveData: 观察者模式领域二三事
查看>>
你必须知道的HTTP基本概念
查看>>
Android ContentProvider调用报错"Bad call:..."及相关Binder权限问题分析
查看>>
基本shell脚本的编辑及变量
查看>>
加密和解密 tar
查看>>
将datatable 保存为 Excel文件(高效率版本)
查看>>
C/C++五大内存分区(转)
查看>>
CentOS 6.5下PXE+Kickstart无人值守安装操作系统
查看>>
xtrapivotcontrol 控件用法及相关属性
查看>>
Shell脚本 常用命令总结 二
查看>>
JS模拟select下拉菜单
查看>>
vmware workstation14永久激活密钥分享
查看>>