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. MySQL中事务的分类

    从事务理论的角度来看,可以把事务分为以下几种类型 扁平事务(Flat Transactions) 带有保存点的扁平事务(Flat Transactions with Savepoints) 链事务(C ...

  2. Web 框架本质解析

    一  Web框架本质 1. 自己开发Web框架 - socket - http协议 - HTML知识 - 数据库(pymysql,SQLAlchemy) HTTP: 无状态.短连接 TCP: 不断开 ...

  3. Python3.6全栈开发实例[019]

    19.干掉主播.现有如下主播收益信息, 按照要求, 完成相应操作:(1)计算主播平均收益值 sum = 0 for i in zhubo.values(): sum +=i print(round(s ...

  4. SaltStack安装配置

    一.环境准备:操作系统CentOS Linux release 7.3.1611master ip:192.168.1.180minion ip:192.168.1.183设置server(maste ...

  5. MySQL数据库(1)_MySQL数据库介绍与安装

    一.数据库相关概念的简介 数据库(database,DB)是指长期存储在计算机内的,有组织,可共享的数据的集合.数据库中的数据按一定的数学模型组织.描述和存储,具有较小的冗余,较高的数据独立性和易扩展 ...

  6. Linux常用的指令(...编辑文件+保存)

    mkdir命令用来创建目录 1 mkdir filename touch命令有两个功能:一是用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来:二是用来创建新的 ...

  7. Hexo 使用中搭建博客过程中遇到的坑

    本地执行hexo s 时报错: WARN No layout: index.html 原因:theme 没有下载下来,经查,theme文件夹下为空. 新建文章后,执行 hexo g 时报如下错误: ( ...

  8. NavigationDrawer和NavigationView-Android M新控件

    Translucent System Bars-4.4新特性 Toolbar-5.0新特性 NavigationDrawer 简介 NavigationDrawer 是 Google 在 Materi ...

  9. Cookie用法简介

    java操作Cookie---javax.servlet.http.Cookie 1.增加一个Cookie Cookie cookie = new Cookie("username" ...

  10. Linux软件包管理 RMP包管理

    概述 RPM 包的命名一般都会遵守统一的命名规则,例如: httpd-2.2.15-15.el6.centos.1.i686.rpm 其中的各项代表的含义如下: httpd:软件包名. 2.2.15: ...