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. js中document的用法

    document.title //设置文档标题等价于HTML的title标签document.bgColor //设置页面背景色document.fgColor //设置前景色(文本颜色)docume ...

  2. Spring3.0.5 获取表中自增的主键(mysql)

    public int addWsstxCotent(final WsstxContent wsstxContent) { final String sql = "insert into ws ...

  3. SqlServer sysobjects_table

    --这是查询所有表的信息 select * from sysobjects where xtype='U'; --这是查询表的数量 select count(*) from sysobjects wh ...

  4. css3的transition效果和transfor效果

    <!doctype html> <html> <head> <meta charset="utf-8" /> <title&g ...

  5. spring3.0事务的配置

    第一种配置方法:基于XML的事务管理 这种方法不需要对原有的业务做任何修改,通过在XML文件中定义需要拦截方法的匹配即可完成配置,要求是,业务处理中的方法的命名要有规律,比如setXxx,xxxUpd ...

  6. DDMS files not found:hprof-conv.exe的解决办法

    或者是you must restart adb and eclipse这类错误 原因:一般是豌豆荚之类的软件影响的,所以,以后要慎用了. 解决方案:先找一下在sdk\tools目录下是否有hprof- ...

  7. 剑指offer-面试题14.调整数组顺序使奇数位于偶数的前面

    题目:输入一个整数数组,实现一个函数来调整该数组中的数字的顺序, 使得所有的奇数位于数组的前半部门,所有的偶数位于数组的后半部门. 这一题一看其实是很简单的,当然在不考虑效率的情况可以这样考虑 我们将 ...

  8. 用B-树实现虚拟图书管理系统

    学校数据结构的课程实验之一. 用到的数据结构:B-树 基本功能:对虚拟书库的图书进行查看.增加.删除.修改. 主函数: #include <iostream> #include " ...

  9. ZOJ 1008 Gnome Tetravex(DFS)

    Gnome Tetravex Time Limit: 10 Seconds      Memory Limit: 32768 KB Hart is engaged in playing an inte ...

  10. [Exception] 当前 TransactionScope 已完成

    本文来自:http://www.cnblogs.com/loafer/archive/2010/06/03/TransactionScopeComplete.html 捕获异常的时候 经常会碰到这个异 ...