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);
        }
    }
  • 相关阅读:
    安装oh-my-zsh
    Ubuntu下安装2017版QQ
    Ubuntu安装Git
    链接libtorrent库时出现的问题
    ubuntu 下重装mysql若干问题
    最简单的epoll的使用范例 : 监听 标准输入 ,并将数据回显到终端
    [转]Linux下CodeBlocks的交叉编译
    各种免费素材下载站点
    Qt5:图片彩色键控,设置图片中指定颜色的像素为透明
    C++:预处理指令
  • 原文地址:https://www.cnblogs.com/smallhester/p/10327466.html
Copyright © 2011-2022 走看看