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

一开始的做法是,先暴力算出一个面,就是n * n的面,能有多少对。记作face

然后从上开始算下来,最上一层,face个,然后第二层,有n * n * (up - 1)个。

递推下去,up是在第i层上面有多少个。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
#define MY "H:/CodeBlocks/project/CompareTwoFile/DataMy.txt", "w", stdout
#define ANS "H:/CodeBlocks/project/CompareTwoFile/DataAns.txt", "w", stdout #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e3 + ;
int e[maxn][maxn];
int a[maxn][maxn];
int tonext[][] = {{, }, {, }, {, }, {, -}, {-, }};
int n;
void work() {
int to = ;
memset(e, , sizeof e);
memset(a, , sizeof a);
for (int i = ; i <= n; ++i) {
for (int j = ; j <= n; ++j) {
a[i][j] = ++to;
}
}
// for (int i = 1; i <= n; ++i) {
// for (int j = 1; j <= n; ++j) {
// cout << a[i][j] << " ";
// }
// cout << endl;
// }
int ans = ;
for (int i = ; i <= n; ++i) {
for (int j = ; j <= n; ++j) {
int t = ans;
for (int k = ; k <= n; ++k) {
for (int h = ; h <= n; ++h) {
bool flag = true;
if (e[a[i][j]][a[k][h]]) continue;
for (int oo = ; oo < ; ++oo) {
int tx = i + tonext[oo][];
int ty = j + tonext[oo][];
if (k == tx && h == ty) {
int dis = abs(a[tx][ty] - a[i][j]);
if (dis == || dis == n || dis == ) {
flag = false;
break;
}
}
}
if (!flag) continue; e[a[i][j]][a[k][h]] = e[a[k][h]][a[i][j]] = ;
ans++;
}
}
//// cout << ans - t << " ";
}
// cout << endl;
}
// cout << ans << endl;
int per = n * n * n;
int toans = ans;
int up = n * n;
for (int i = ; i <= n; ++i) {
toans += ans;
toans += (n * n) * (up - );
up += n * n;
}
cout << toans << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
IOS;
while (cin >> n) work();
return ;
}

逆向思维。

一共有C(n * n * n, 2)对。然后减去4个面的。

一行有n - 1对4个面的,有n行,同样,有n列。然后还有n竖,所以是三种。

每一种,在一个面上,有(n - 1) * n,一个体上,有(n - 1) * n * n,所以减去3 * all

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
#define MY "H:/CodeBlocks/project/CompareTwoFile/DataMy.txt", "w", stdout
#define ANS "H:/CodeBlocks/project/CompareTwoFile/DataAns.txt", "w", stdout #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
int C(int n, int m) {
int ans = ;
for (int i = ; i <= m; ++i) {
ans = ans * (n - i + ) / i;
}
return ans;
}
int n;
void work() {
cout << C(n * n * n, ) - (n - ) * n * n * << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
IOS;
while (cin >> n) work();
return ;
}

HDU 1220 B - Cube的更多相关文章

  1. HDU 1220 Cube(数学,找规律)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    M ...

  2. 题解报告:hdu 1220 Cube

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1220 问题描述 Cowl擅长解决数学问题. 有一天,一位朋友问他这样一个问题:给你一个边长为N的立方体 ...

  3. Cube HDU - 1220(思维)

    Cowl is good at solving math problems. One day a friend asked him such a question: You are given a c ...

  4. B - Cube HDU - 1220 (数学计数)

    题意:一个边长为N的正方体,切割成N*N*N个单位正方体,问有多少对正方体之间有0个,2个公共点. 思路:因为正方体之间出现公共点的情况有0,2,4. 那么直接正面求,肯定不好求,那么先求出有4个公共 ...

  5. hdu 1220 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. HDU 5292 Pocket Cube 结论题

    Pocket Cube 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5292 Description Pocket Cube is the 2×2× ...

  7. hdu 3547 DIY Cube (Ploya定理)

    DIY Cube Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total S ...

  8. HDU 4801 Pocket Cube

    题目链接 去年现场,虎哥1Y的,现在刷刷题,找找状态... 一共6种转法,把3个面放到顶部,左旋和右旋,感觉写的还不错....都写成常数了. #include <stdio.h> #inc ...

  9. HDU 1220 简单数学题

    题目大意是 在魔方上找到有多少对小立方块它们之间连接的点不超过两个 因为任意两个立方块之间相连的点就只有0,1,2,4 这样4种情况 那么我们只需要考虑总共的组成立方块对数 sum = C(2 , n ...

随机推荐

  1. FFT用到的各种素数

    int MOD; inline int mul(int a, int b){ return (long long)a * b % MOD; } int power(int a, int b){ ; ) ...

  2. yum报错File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:

    原因:学python的时候,把centos7自带的python2.7改成了python3.6.2.而yum使用的是python2,所以会出现yum报错. 解决方法: 在文件/usr/bin/yum./ ...

  3. jQuery 怎么获取对象

    1.JQuery的核心的一些方法 each(callback) '就像循环 $("Element").length; ‘元素的个数,是个属性 $("Element&quo ...

  4. strncpy和strlen的可能的实现

    #include <stdio.h> #include <stdlib.h>//为避免与标准库中的函数发生混淆,我将它们命名为stringNCopy和stringLength ...

  5. HDU 5687 Problem C

    Problem C Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  6. MYSQL初级学习笔记八:MySQL中常用的函数!(视频序号:初级_45-50)

    知识点十:MySQL中的函数(45-50) 数学函数: 名称 描述 CEIL() 进一取整 FLOOR() 舍一取整 MOD 取余数(取摸) POWER() 幂运算 ROUND() 四舍五入 TRUN ...

  7. Mysql语句示例

    Mysql语句示例 最常用 sql 语句总结 前言 Mysql 是数据库开发使用的主要平台之一.sql 的学习掌握与使用是数据库开发的基础,此处展示详细sql 语句的写法,及各种功能下的 sql 语句 ...

  8. CodeForces985F:Isomorphic Strings (字符串&hash)

    题意:取出字符串Str里的两个串S,T,问对应位置的的字符在否有一一映射关系. hash:对于每个字符s=‘a’-‘z’,我们任意找一个i,满足Si==s,(代码里用lower_bound在区间找到最 ...

  9. unity aSSETBUNDEL (转)

    无论是模型资源还是UI资源,最好是先把他们放在Prefab中,然后在做成Assetbundle.我们以模型来举例,Assetbundle中可以放一个模型.也可以放多个模型,它是非常灵活了那么最需要考虑 ...

  10. COCOS2DX场景切换特效

    cocos2d-x 3.0中场景切换特效比较多,而且游戏开发中也经常需要用到这些特效,来使场景切换时不至于那么干巴,遂这里汇总一下,开发中使用. 百牛信息技术bainiu.ltd整理发布于博客园 场景 ...