现在的位置: 首页 > 综合 > 正文

HDU 1220 Cube

2018年05月02日 ⁄ 综合 ⁄ 共 826字 ⁄ 字号 评论关闭
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
题意:给你一个正方体,切割成单位体积的小正方体,求所有公共顶点数<=2的小正方体的对数。 公共点的数目只可能有:0,1,2,4. 很明显我们用总的对数减掉有四个公共点
然后 自己画一个边长为3的正方体想想
#include<iostream>
using namespace std;
#include<stdio.h>
int main()
{
       int  n;
       while(cin>>n)
       {
           printf("%d\n",(n*n*n)*(n*n*n-1)/2-3*(n-1)*n*n);
       }
       return 0;
}

抱歉!评论已关闭.