HDOJ--1220--Cube

来源:互联网 发布:景甜面相分析知乎 编辑:程序博客网 时间:2024/05/21 20:25

Cube

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


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
123
 

Sample Output
016297
Hint
Hint
The results will not exceed int type.
 
 
题目大意:给你一个立方体,让你将它分割为一个一个的小立方体,然后问你这些小立方体中,公共点的个数《=2个的立方体有多少对。恩,数学推理问题。解决的方法就在于一个公式。表示并不会推导这个公式,数学规律总结这种事情一向是比较薄弱的一环。

AC代码:
#include<stdio.h>#include<string.h>#include<math.h>using namespace std;int main(){int n;while(scanf("%d",&n)!=EOF){if(n==1){printf("0\n");continue;}printf("%d\n",n*n*n*(n*n*n-1)/2-3*n*n*(n-1));}return 0;}


0 0
原创粉丝点击