zoukankan      html  css  js  c++  java
  • 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);
        }
    }
  • 相关阅读:
    分页系统
    ORM-数据处理
    Django的用法
    登录cookie写法
    MySQL数据库的安装创建
    前端弹框编写
    ADB常用指令
    Appium环境配置
    Jmeter中传递cookie值
    Jmeter从文件中读取参数值
  • 原文地址:https://www.cnblogs.com/smallhester/p/10327466.html
Copyright © 2011-2022 走看看