杭电1220--Cube

Cube

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1562    Accepted Submission(s): 1243

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

The results will not exceed int type.

Author

Gao Bo

Source

杭州电子科技大学第三届程序设计大赛

Recommend

Ignatius.L   |   We have carefully selected several similar problems for you:  1221 1225 1222 1224 3450

题意:

给你一个正方体,切割成单位体积的小正方体,求所有公共顶点数<=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);

 1 #include <stdio.h>
 2 int main()
 3 {
 4     int n ;
 5     while(~scanf("%d", &n))
 6     {
 7         int num = n*n*n*(n*n*n-1)/2 - n*n*(n-1)*3 ;
 8         printf("%d\n", num) ;
 9     }
10     return 0 ;
11 }
时间: 2024-11-08 01:52:09

杭电1220--Cube的相关文章

杭电ACM1220——Cube~~简单的数学题

题目的意思是给你一个立方体的棱长 n ,将这个立方体分解成单位长度为1的小立方体.问这个大立方体分解之后的n * n * n个小立方体中有多少对小立方体的公共点不超过2个. 立方体分解之后,只会出现 0, 1, 2, 4个公共点的情况,所以算出所以的对数,然后减去4个公共点的情况就可以解决了. 关键是4个公共点的情况有多少对? 首先是有3个面没有露出来,总共只有8个,也就是那8个顶点,所以有 3 * 8对. 然后是有4个面没有露出来,总共有(n - 2)* 12种,所以有4 *  (n - 2)

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

杭电ACM题目分类

杭电ACM题目分类 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028. 1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092. 1093.1094.1095.1096.1097.1098.1106.1108.1157.1163.1164.1170.1194.1196. 1197.1201.1202.1205.1219.1234.123

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

hdu 1016 Prime Ring Problem DFS解法 纪念我在杭电的第一百题

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29577    Accepted Submission(s): 13188 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

一个人的旅行 HDU杭电2066【dijkstra算法】

http://acm.hdu.edu.cn/showproblem.php?pid=2066 Problem Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景--草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯粹看雪景,去巴黎喝咖啡写信,去北京探望孟姜女--眼看寒假就快到了,这么一大段时间,可不

杭电1162--Eddy&#39;s picture(Prim()算法)

Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8070    Accepted Submission(s): 4084 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to b

杭电1276--士兵队列训练问题

士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4605    Accepted Submission(s): 2148 Problem Description 某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行

杭电1272 并查集找环+判断连通

杭电1272 并查集找环+判断连通 E - E Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1272 Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B