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。

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define LL long long
LL qpow(LL a,LL b){LL r=;for(;b;b>>=,a=a*a)if(b&)r=r*a;return r;}
int main()
{
LL n;
while(cin>>n)
cout<<((n*n*n)*(n*n*n-)/-*(n-)*n*n)<<endl;
return ;
}

hdu 1220 容斥的更多相关文章

  1. HDU 4135 容斥

    问a,b区间内与n互质个数,a,b<=1e15,n<=1e9 n才1e9考虑分解对因子的组合进行容斥,因为19个最小的不同素数乘积即已大于LL了,枚举状态复杂度不会很高.然后差分就好了. ...

  2. HDU 2841 容斥 或 反演

    $n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 284 ...

  3. HDU 1695 容斥

    又是求gcd=k的题,稍微有点不同的是,(i,j)有偏序关系,直接分块好像会出现问题,还好数据规模很小,直接暴力求就行了. /** @Date : 2017-09-15 18:21:35 * @Fil ...

  4. HDU 4059 容斥初步练习

    #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...

  5. Co-prime HDU - 4135_容斥计数

    Code: #include<cstdio> #include<cstring> #include<cmath> #include<iostream> ...

  6. How many integers can you find HDU - 1796_容斥计数

    Code: #include<cstdio> using namespace std; typedef long long ll; const int R=13; ll a[R]; ll ...

  7. hdu 5792(树状数组,容斥) World is Exploding

    hdu 5792 要找的无非就是一个上升的仅有两个的序列和一个下降的仅有两个的序列,按照容斥的思想,肯定就是所有的上升的乘以所有的下降的,然后再减去重复的情况. 先用树状数组求出lx[i](在第 i ...

  8. HDU 1695 GCD 容斥

    GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...

  9. HDU 5794 A Simple Chess (容斥+DP+Lucas)

    A Simple Chess 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5794 Description There is a n×m board ...

随机推荐

  1. spring 编译时抱错纪录class path resource [spring/] cannot be resolved to URL because it does not exist

    class path resource [spring/] cannot be resolved to URL because it does not exist; 在 pom.xml 里添加如下代码 ...

  2. 两个div同时滚动

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  3. 解决svnserve: Can't bind server socket: Address already in use

    最近在忙着搭建jenkins系统集成版本控制和git分布式版本控制,其中涉及到了点svn方面的,由于自己也是第一次搭建svn,挺顺利的,中间遇到点小问题: 我使用的是yum安装的svn,安装完成配置结 ...

  4. django基本安装

    一.web框架 1.什么是web框架? Web框架是一种开发框架,用来支持动态网站.网络应用程序及网络服务的开发.其类型有基于请求的和基于组件的两种框架. 本质上其实就是一个socket服务端,用户的 ...

  5. requirejs神奇问题,data-main修改后,刷新没有重新载入

    同事在使用require的时候,在配置地方增加 urlArgs: "bust=" +  (new Date()).getTime(), 然后问题又来了,这个相当于js版本的东东会把 ...

  6. try catch 事务不会滚

    在spring机制中,在配置事务后,如果采用try catch 捕获异常后,因为异常已经被捕获,所以事务不会滚,从而产生许多脏数据.解决办法: 1.在catch中抛出异常,(throw new Run ...

  7. php……流程

    流程:由两个及以上的业务步骤,完成一个完整的业务行为的过程,可称之为流程:注意是两个及以上的业务步骤.事物进行过程中的次序或顺序的布置和安排. 创建页面: 登录页面(login.php): <h ...

  8. 解决 flex align-items:center 无法居中(微信小程序)

    因为最近再做小程序,需要用到flex布局,因为写惯了web项目,初次学习确实感弹性布局的强大(关键是不用再管可恶的ie了). 但是也遇到了align-items:center无法居中的问题,想了很久终 ...

  9. C# 学习黑马.Net视频教程,大文件拷贝

    设计器代码: namespace 大文件拷贝 { partial class Form1 { /// <summary> /// 必需的设计器变量. /// </summary> ...

  10. C51数据类型