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.
 
Sample Input
1
2
3
Sample Output
0
16
297
 
这纯粹是一道数学题目,推理如下:
给你一个正方体,切割成单位体积的小正方体,求所有公共顶点数<=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) - 3*n^2(n-1)

 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
int num;
while(cin>>num)
{
int sum=(pow(num,)*(pow(num,)-)/)-pow(num,)**(num-);
cout<<sum<<endl;
}
}

Cube(hd1220)的更多相关文章

  1. ZOJ 2477 Magic Cube(魔方)

    ZOJ 2477 Magic Cube(魔方) Time Limit: 2 Seconds      Memory Limit: 65536 KB This is a very popular gam ...

  2. PLSQL_基础系列02_分组函数GROUP BY / ROLLUP / CUBE(案例)

    2014-11-30 Created By BaoXinjian

  3. stm32.cube(一)——系统架构及目录结构

    一.前言 Arm的应用场景往往比51单片机复杂得多,如果一个高级应用的开发需要连底层的结构性代码都要重构,那么在成本和研发周期上就会面临巨大的风险.为了简化编码过程,芯片厂商经常会提供一些板卡级支持的 ...

  4. 《BI项目笔记》创建多维数据集Cube(1)

    有两个事实表,因此就有两个度量值组,并且向导将为非维度键的事实表中的每一个数值列创建一个度量值.由于我们这里不需要那么多,所以只选择部分度量值.另外要注意,度量值的名称源于事实表中的列,所有名称由可能 ...

  5. 《BI项目笔记》创建多维数据集Cube(2)

    本节建立: 历年的初烟水分均值变化分析Cube:区域维度:地州,专县时间维度:年等级维度:大等级,小等级指标:水分均值 数据源视图: 数据处理: ) ) DELETE FROM T_QualMoist ...

  6. Cube(规律)

    Cube Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  7. hdoj--5053--the Sum of Cube(水)

    the Sum of Cube Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tot ...

  8. 【HDOJ6330】Visual Cube(模拟)

    题意: 思路: import java.util.Scanner; public class Main { public static void main(String args[]) { Scann ...

  9. HDU 3584 Cube(三位树状数组)

    Cube Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submi ...

随机推荐

  1. python一句代码建立树

    from collections import defaultdict def tree(): return defaultdict(tree) 上面的代码不难理解,就是利用递归的方式,创建了一个树的 ...

  2. 使用jekyll主题

    github上面有很多基于jekyll的主题 https://github.com/theme4jekyll 使用起来也非常方便.直接clone到本地 这些主题,包括了很多模板,在新建博客的时候可以在 ...

  3. kururu的VHDL学习笔记

    最近开始做课程设计,VHDL设计一个中央空调的控制程序.所以开始学习VHDL,在这篇文章里面记录一些自己的笔记,期望对于同样的初学者有些借鉴意义~ 编写VHDL所需的工具: 那自然很是quartus啦 ...

  4. ubuntu 中c 语言编程(学习)

    ubuntu下c编程 c编程中相关文件后缀 .a    静态库(archive .c     C源代码(需要编译预处理) .h     C源代码头文件 .i      C源代码 (不需要编译预处理) ...

  5. FLASH 存储学习-串行SPI nor

    1.1 SST25VF080B简介 1.1.1 主要特性 关键点:容量.速度(时钟速度.读写速度).功耗. 容量:8MBit: 最高SPI时钟频率:50MHz: 低功耗模式下电流消耗:5uA,正常读模 ...

  6. c++容器使用总结(转载)

    目录 ==================================================== 第一章 容器 第二章 Vector和string 第三章 关联容器 第四章 迭代器 第五 ...

  7. Debug of bash , perl and python

    1.bash -x   script 2.perl -d  script 3. python -m pdb script n: execute the next line s: execute the ...

  8. os x 10.10 測试版系统下载 swift语言学习资料下载

    http://pan.baidu.com/s/1eQ5oj1S               这是下载地址 ! 刚学完oc 就出了 swift!这----  只是还是非常高兴看了一点swith得东西感觉 ...

  9. SPOJ GCDEX (数论)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:求sigma (gcd (i , j))  ...

  10. 把Storyboard减轻的方法

    把Storyboard减轻的方法 by 伍雪颖 UIViewController *secondStoryboard = [[UIStoryboard storyboardWithName:@&quo ...