Cube
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 972    Accepted Submission(s): 775

Problem Description
Cowl is good at solving math problems. One day a friend asked him such a question: You are given a cube whose edge length is N, it is cut by the planes that was paralleled to its side planes into N * N * N unit cubes. Two unit cubes may have no common points or two common points or four common points. Your job is to calculate how many pairs of unit cubes that have no more than two common points.

Process to the end of file.

 

Input
There will be many test cases. Each test case will only give the edge length N of a cube in one line. N is a positive integer(1<=N<=30).
 

Output
For each test case, you should output the number of pairs that was described above in one line.
 

Sample Input
1
2
3
 

Sample Output
0
16
297
Hint

Hint

The results will not exceed int type.

 

Author
Gao Bo
 

Source
 

Recommend
Ignatius.L
 

给你一个正方体,切割成单位体积的小正方体,求所有公共顶点数<=2的小正方体的对数。公共点的数目只可能有:0,1,2,4.很明显我们用总的对数减掉有四个公共点的对数就可以了。
总的公共点对数:n^3*(n^3-1)/2(一共有
n^3块小方块,从中选出2块
)(只有两个小方块之间才存在公共点,我们从所有的小方块中任意选出两个,自然就确定了这两个小方块的公共点的对数,从所有小方块中任意选取两个,总得选取方法数就是所有种类对数数目的总和!)
公共点为4的对数:一列有n-1对(n个小方块,相邻的两个为一对符合要求),一个面的共有 n^2列,底面和左面,前面三个方向相同,同理可得,故总数为:3*n^2(n-1)
所以结果为:n^3 * (n^3-1) - 3*n^2(n-1)

HDOJ 1220 Cube的更多相关文章

  1. HDU 1220 Cube(数学,找规律)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    M ...

  2. 题解报告:hdu 1220 Cube

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1220 问题描述 Cowl擅长解决数学问题. 有一天,一位朋友问他这样一个问题:给你一个边长为N的立方体 ...

  3. hdu 1220 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  4. 2018年暑假ACM个人训练题7 题解报告

    A:HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用) B:(还需要研究一下.....) C:HDU 1071 The area(求三个点确定的抛物线的面积, ...

  5. HDOJ 3547 DIY Cube 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3547 题目大意:求用$C$种颜色给立方体的8个顶点染色的本质不同的方法.两种方法本质不同即不能通过旋转 ...

  6. 【HDOJ】4801 Pocket Cube 的几种解法和优化

    1. 题目描述给定一个$2 \times 2 \times 2$的魔方,当某个面上的4个小块颜色均相同时,称这个面为complete.求对这个魔方进行$n \in [1,7]$次旋转(沿某个面顺时针或 ...

  7. Cube HDU - 1220(思维)

    Cowl is good at solving math problems. One day a friend asked him such a question: You are given a c ...

  8. HDU 1220 B - Cube

    http://acm.hdu.edu.cn/showproblem.php?pid=1220 一开始的做法是,先暴力算出一个面,就是n * n的面,能有多少对.记作face 然后从上开始算下来,最上一 ...

  9. 【HDOJ】3584 Cube

    三位树状数组. /* 3584 */ #include <iostream> #include <string> #include <map> #include & ...

随机推荐

  1. Windows Server 2003开机自动启动MySQL服务设置方法

    Windows Server 2003开机自动启动MySQL服务设置方法 发布时间:2014-12-19 更新时间:2014-12-24 来源:网络 作者:eaglezhong 关键词: 2003 e ...

  2. 射击比赛 (POJ 1719) 题解

    [问题描述] 我们假设射击的目标是一个由R*C(2≤R≤C≤ 1000)个小方格组成的矩形网格.网格中每一列恰有2个白色的小方格和R-2个黑色的小方格.定义网格的行从顶至底编号为1~R,列从左至右编号 ...

  3. C# 修改IE 源代码参照样例

    using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; ...

  4. hadoop-cdh with snappy

    hadoop: 2.5.0-cdh5.3.6 snappy: 1.1.3 hadoop 2.*不需要hadoop-snappy.只要机器上安装好snappy, 直接编译就可以 编译命令: mvn cl ...

  5. 记一个python+sqlalchemy+tornado的一个高并发下,产生重复记录的bug

    场景:在用户通过支付通道支付完成返回时,发现我收到的处理数据记录中有两条同样的数据记录, 也就是同一笔钱,我数据库中记为了两条一样的记录. tornado端代码 from tornado import ...

  6. Python学习教程(learning Python)--2.3.4Python函数返回值

    本节讨论Python函数返回值问题. Python和C语言一样,也可以在函数结束时返回一个值.但在定义自己的Python函数时,是不需要指定返回值数据类型的,这和Python不关心变量的数据类型是一致 ...

  7. hdu 4255 A Famous Grid

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4255 A Famous Grid Description Mr. B has recently dis ...

  8. c/c++常用代码 -- ini文件操作

    #pragma once #include <string> #include <sstream> typedef std::basic_string<TCHAR> ...

  9. flask中文问题

    在使用flask时在模板中使用了中文,运行的时候遇到下面的问题: UnicodeDecodeError UnicodeDecodeError: 'utf8' codec can't decode by ...

  10. 35.在PCB中删除元件

    在PCB Editor里面,如果想进行什么操作,首先得点击这个命令,再点击你要操作的区域/元件,最后右键选择"Done",这样你才能完成一个操作.