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. 关于 jQuery中 function( window, undefined ) 写法的原因

    今天在读 jQuery 源码的时候,发现下面的写法: (function(window,undefined){ ...// code goes here })(window); window 作为参数 ...

  2. C++----练习--while求和

    1.完成1+2+3+...+99+100 #include<iostream> int main() { std::cout<<"本程序完成1 + 2 + 3 ... ...

  3. Blog透视镜

    Blog透视镜,提供了Blog代码示例,文章和教程,可以帮助你建置博客. 网站名称:Blog透视镜 网站地址:http://blog.openyu.org

  4. jQuery插件之artDialog

    artDialog是一个非常强大的弹出框插件.默认有两个版本,一个是jQuery版,一个是javascript版.功能非常多,而且使用非常简单.不写了,直接贴上官网的预览运行地址,以后用得着的时候去那 ...

  5. Android Animations 视图动画使用详解!!!

    转自:http://www.open-open.com/lib/view/open1335777066015.html Android Animations 视图动画使用详解 一.动画类型 Andro ...

  6. HDU 3308 LCIS(线段树单点更新区间合并)

    LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...

  7. ubuntu下hadoop完全分布式部署

    三台机器分别命名为: hadoop-master ip:192.168.0.25 hadoop-slave1 ip:192.168.0.26 hadoop-slave2 ip:192.168.0.27 ...

  8. The Building Blocks- Components of EA Part 2- Process, People, Network and Time

    1. Zachman Framework Information (Data) - Answer the Question 'What?' Contextual: List of Things imp ...

  9. libaio under MIPS architecture /在mips架构下使用的libaio

    First, you can find libaio source in http://libaio.sourcearchive.com/ Second,download the libaio_0.3 ...

  10. c语言的lua库编写

    gcc编译 gcc -I/usr/local/include/ -L/usr/local/lib/ -lm -o engine_mlisten_lua ./src/engine_mlisten_lua ...