zoukankan      html  css  js  c++  java
  • hdu 1220 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=1220

    Cube

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 2260    Accepted Submission(s): 1819


    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
    Hint
    Hint
    The results will not exceed int type.
         
           对于一个N*N*N的立方体,问有几对小立方体满足公共点个数<=2,由于题目中说了这个数目只有三种情况0/2/4,我们可以让总组合数减去交点是4的对数就是答案,全部方案个数就是C(N*N*N,2)
    有四个公共顶点也就是说有公共面,可能位于水平线上或者垂线上或者纵线上,类似于xyz轴,显然对于每一行/列/垂线上都有(N-1)对,这个结果就是3*(N-1)*N*N,因为有N*N个x/y/z。
      
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstring>
     5 using namespace std;
     6 #define LL long long
     7 LL qpow(LL a,LL b){LL r=1;for(;b;b>>=1,a=a*a)if(b&1)r=r*a;return r;}
     8 int main()
     9 {
    10     LL n;
    11     while(cin>>n)
    12         cout<<((n*n*n)*(n*n*n-1)/2-3*(n-1)*n*n)<<endl;
    13     return 0;
    14 }
  • 相关阅读:
    CentOS更改yum源与更新系统
    JQ兼容各种JS库的写法
    虚拟主机
    SSH安全登录(远程管理)22端口
    Samba服务器
    VSFTP服务
    网络配置和文件服务器
    服务和进程管理(二)
    攻防世界XCTF--一个登录验证页面(第六题)
    攻防世界XCTF--一个不能按的按钮(第五题)
  • 原文地址:https://www.cnblogs.com/zzqc/p/7576596.html
Copyright © 2011-2022 走看看