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 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;while(scanf("%lld", &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("%lld %lld %lld %lld %lld %lld\n", 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)

转载于:https://www.cnblogs.com/liaoguifa/archive/2013/03/05/2945042.html

Uva 10177 - (2/3/4)-D Sqr/Rects/Cubes/Boxes?相关推荐

  1. UVa Online Judge 工具網站

    UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...

  2. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  3. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  4. 提取了下刘汝佳推荐的题号...

    今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started    10055 - Hashmat the Brave Warrior ...

  5. ACMer Training 学习指导

    本文原地址 一.UVaOJ http://uva.onlinejudge.org 西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ. 二.<算法竞赛入门经典> ...

  6. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  7. AOAPC I: Beginning Algorithm Contests 题解

    AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...

  8. ICPC程序设计题解书籍系列之八:(美)斯基纳等:《挑战编程-程序设计竞赛训练手册》

    S书<挑战编程--程序设计竞赛训练手册>题目一览 1 Getting Started UVA100 POJ1207 HDU1032 The 3n + 1 problem[水题] - 海岛B ...

  9. 初学者acm的练习题指南

    上机练习题参考题 忘了在哪找的啦~~希望对大家有帮助呦 <!--[if !supportLists]-->1.    <!--[endif]-->Programming Bas ...

最新文章

  1. NLP中的情感分析可参考该篇 CNN文本分类
  2. Linux学习总结(9)——Linux 新手必知必会的 10 条 Linux 基本命令
  3. gradle中的增量构建
  4. srve0255e尚未定义要怎么办_皮肤干燥怎么办?四大方法帮你冬季补?
  5. Luogu1443 马的遍历【STL通俗BFS】
  6. 前端学习(2534)vue源码解析
  7. LeetCode刷题(16)
  8. Linux统计文件夹下文件数量
  9. 安装VS2010旗舰版出错,返回错误码1603
  10. python xlrd 写入已有的excel并保留原excel格式
  11. 牛客网Verilog快速入门题目收获——异步复位的串联T触发器(VL2)
  12. 十大免费cms建站系统介绍推荐
  13. [转]多普达818、828+升级中文WM6.1及必装软件全过程讲解
  14. 自动激活win7系统的bat文件
  15. 08-小蜜蜂单片机定时器
  16. C语言习题11.3,用指针数组编程输出月份的英文表示
  17. sso php 实现,Jasny-SSO
  18. js 获取字符串长度方法length
  19. IT码农进入日企之路——模拟试题
  20. 淘宝爆款的误区,怎么合力打造爆款流量

热门文章

  1. php 偷偷转移别人权重,判断百度蜘蛛偷偷进行301转移权重 给新站提权
  2. 上古卷轴3晨风职业_上古卷轴3:晨风
  3. 软件质量保证计划_软件测试计划 笔记
  4. linux中文件记录的时间参数,【Linux】stat命令查看文件的三个时间参数
  5. office插件开发_Visual Studio Code有哪些你常用的插件?
  6. mysql在线教程嵌套_MySQL update嵌套
  7. 【Java】使用单向链表实现一个队列(Queue)
  8. 网络的塔建+模型训练
  9. [JSOI2008]星球大战 并查集
  10. Power Network [POJ - 1459]