我是靠谱客的博主 内向咖啡,最近开发中收集的这篇文章主要介绍hdu 1220 Cube 简单数论Cube,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Cube

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


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.
/*
给你一个边长n的正方体,切割成n*n*n个单位体积的小正方体,求所有公共顶点数<=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) / 2 - 3*n^2(n-1)  
*/
#include <stdio.h>

int main()
{
	int n ;
	while(~scanf("%d",&n))
	{
		printf("%dn",n*n*n*(n*n*n-1)/2-3*(n-1)*n*n);
	}
	return 0 ;
}

与君共勉

最后

以上就是内向咖啡为你收集整理的hdu 1220 Cube 简单数论Cube的全部内容,希望文章能够帮你解决hdu 1220 Cube 简单数论Cube所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部