• Cube HDU


    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. 

    InputThere 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). 
    OutputFor 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*n*n个长度为1的立方体,求相邻的点小于等于两个的个数
    题解:相反考虑,排列组合,结合切好后的总表面积和一开始的表面积
    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<sstream>
    #include<cmath>
    #include<stack>
    #include<cstdlib>
    #include <vector>
    #include<queue>
    using namespace std;
    
    #define ll long long
    #define llu unsigned long long
    #define INF 0x3f3f3f3f
    #define PI acos(-1.0)
    const int maxn =  1e5+5;
    const int  mod = 1e9+7;
    
    int main()
    {
        ll n;
        while(~scanf("%lld",&n))
        {
            ll sum = ((n*n*n)*((n*n*n)-1))/2 - (6*n*n*n - 6*n*n)/2;
            printf("%lld
    ",sum);
        }
    }
  • 相关阅读:
    Gridview全选
    Gridview中绑定DropDownList
    图片流Base64编码 转图片
    jQuery 效果
    纯虚函数与抽象类
    c++的内存分配
    sizeof数据对齐问题
    C++中类所占的存储空间
    成员函数实现在类定义中与在类定义外的区别
    C++成员函数的存储方式
  • 原文地址:https://www.cnblogs.com/smallhester/p/10327466.html
Copyright © 2020-2023  润新知