hdu 1220 Cube (数学)

题目

Cube

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.
 
 思路:      对于任何两个单位立方体,交点个数的情况有0个、1个、2个、4个;2个公共点时,有一条公共边;4个公共点时,有一个公共面。
             这题 求不多于两个公共点的单位立方体的对数,则可先求出4个公共点的单位立方体的对数。
 
             4个交点的立方体对是两个立方体共面的情况,求出大的立方体一共有多少个单位面积的公共面;
             即所有单位立方体的面数6*n^3减去在大立方体表面的面数6*n^2就可以了
 
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int n,m;
 5     while(~scanf("%d",&n))
 6     {
 7         m=(n*n*n*(n*n*n-1)/2)-(6*n*n*n-6*n*n)/2;
 8         printf("%d\n",m);
 9     }
10 }
View Code

 

 

 

posted @ 2013-06-03 16:54  lysr__tlp  阅读(554)  评论(0编辑  收藏  举报