【HDU - 1220】【Cube】

题目:

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.

Hint

Hint
      

解题报告:给定一个长度为n的正方立体,用平面切割为n^3个大小相等的小正方体,为有多少对(两个正方体)的交点不超过4个的数目。上来居然想跑斐波那契,想想真的是呆了,这道题目六个月之前做过,很尴尬,总结了规律:你会发现任意两个正方体的相交的点的数目为0 1 2 4,求解不超过2的点的正方体对数,你会发现只要减去相交点数为4的就可以,总结公式,一共有n^3个正方体,选出两个C(n^2,2)为总数,相交点数大于4的对数为 (n-1)*n*n*3(n-1为一行/列/竖的对数,n*n是总行数,3的话是3个方向)二者做差就可以得到答案。

ac代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		printf("%d\n",n*n*n*(n*n*n-1)/2-3*n*n*(n-1));
	}
	return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值