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

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

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

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

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #define IOS ios::sync_with_stdio(false)
  7. using namespace std;
  8. #define inf (0x3f3f3f3f)
  9. typedef long long int LL;
  10. #define MY "H:/CodeBlocks/project/CompareTwoFile/DataMy.txt", "w", stdout
  11. #define ANS "H:/CodeBlocks/project/CompareTwoFile/DataAns.txt", "w", stdout
  12.  
  13. #include <iostream>
  14. #include <sstream>
  15. #include <vector>
  16. #include <set>
  17. #include <map>
  18. #include <queue>
  19. #include <string>
  20. const int maxn = 1e3 + ;
  21. int e[maxn][maxn];
  22. int a[maxn][maxn];
  23. int tonext[][] = {{, }, {, }, {, }, {, -}, {-, }};
  24. int n;
  25. void work() {
  26. int to = ;
  27. memset(e, , sizeof e);
  28. memset(a, , sizeof a);
  29. for (int i = ; i <= n; ++i) {
  30. for (int j = ; j <= n; ++j) {
  31. a[i][j] = ++to;
  32. }
  33. }
  34. // for (int i = 1; i <= n; ++i) {
  35. // for (int j = 1; j <= n; ++j) {
  36. // cout << a[i][j] << " ";
  37. // }
  38. // cout << endl;
  39. // }
  40. int ans = ;
  41. for (int i = ; i <= n; ++i) {
  42. for (int j = ; j <= n; ++j) {
  43. int t = ans;
  44. for (int k = ; k <= n; ++k) {
  45. for (int h = ; h <= n; ++h) {
  46. bool flag = true;
  47. if (e[a[i][j]][a[k][h]]) continue;
  48. for (int oo = ; oo < ; ++oo) {
  49. int tx = i + tonext[oo][];
  50. int ty = j + tonext[oo][];
  51. if (k == tx && h == ty) {
  52. int dis = abs(a[tx][ty] - a[i][j]);
  53. if (dis == || dis == n || dis == ) {
  54. flag = false;
  55. break;
  56. }
  57. }
  58. }
  59. if (!flag) continue;
  60.  
  61. e[a[i][j]][a[k][h]] = e[a[k][h]][a[i][j]] = ;
  62. ans++;
  63. }
  64. }
  65. //// cout << ans - t << " ";
  66. }
  67. // cout << endl;
  68. }
  69. // cout << ans << endl;
  70. int per = n * n * n;
  71. int toans = ans;
  72. int up = n * n;
  73. for (int i = ; i <= n; ++i) {
  74. toans += ans;
  75. toans += (n * n) * (up - );
  76. up += n * n;
  77. }
  78. cout << toans << endl;
  79. }
  80.  
  81. int main() {
  82. #ifdef local
  83. freopen("data.txt","r",stdin);
  84. #endif
  85. IOS;
  86. while (cin >> n) work();
  87. return ;
  88. }

逆向思维。

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

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

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

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #define IOS ios::sync_with_stdio(false)
  7. using namespace std;
  8. #define inf (0x3f3f3f3f)
  9. typedef long long int LL;
  10. #define MY "H:/CodeBlocks/project/CompareTwoFile/DataMy.txt", "w", stdout
  11. #define ANS "H:/CodeBlocks/project/CompareTwoFile/DataAns.txt", "w", stdout
  12.  
  13. #include <iostream>
  14. #include <sstream>
  15. #include <vector>
  16. #include <set>
  17. #include <map>
  18. #include <queue>
  19. #include <string>
  20. int C(int n, int m) {
  21. int ans = ;
  22. for (int i = ; i <= m; ++i) {
  23. ans = ans * (n - i + ) / i;
  24. }
  25. return ans;
  26. }
  27. int n;
  28. void work() {
  29. cout << C(n * n * n, ) - (n - ) * n * n * << endl;
  30. }
  31.  
  32. int main() {
  33. #ifdef local
  34. freopen("data.txt","r",stdin);
  35. #endif
  36. IOS;
  37. while (cin >> n) work();
  38. return ;
  39. }

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. Java-JDK-bin-Java-JR

    Java in JDK\bin vs. Java in JRE\bin (Java in General forum at Coderanch) https://coderanch.com/t/385 ...

  2. How MySQL Opens and Closes Tables refuse connections 拒绝连接的原因 file descriptors

    MySQL :: MySQL 5.7 Reference Manual :: 8.4.3.1 How MySQL Opens and Closes Tables https://dev.mysql.c ...

  3. JSON与localStorage的爱恨情仇

    在使用localStorage时,我们会给一个key存取一个value,这个value可以是一个普通的字符串,也可以是一个对象,如果是一个字符串,我们就需要通过JSON.stringify来转化为JS ...

  4. luogu2704 炮兵阵地 状态压缩DP

    题目大意:一个N*M的地图由N行M列组成,地图的每一格可能是山地(用“H” 表示),也可能是平原(用“P”表示),在每一格平原地形上最多可以布置一支炮兵部队,能攻击到的区域:沿横向左右各两格,沿纵向上 ...

  5. CLI和CGI的区别

    CGI :“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上.以CGI方式运行时,web s ...

  6. Hadoop 中的 (side data) 边数据

    一.用途 边数据是作业所需的额外的只读数据,通常用来辅助主数据集: 二.方法 1.利用Configuration类来配置,利用setter()和getter()可方便的使用,方便存储一些基本的类型: ...

  7. YTU 2802: 判断字符串是否为回文

    2802: 判断字符串是否为回文 时间限制: 1 Sec  内存限制: 128 MB 提交: 348  解决: 246 题目描述 编写程序,判断输入的一个字符串是否为回文.若是则输出"Yes ...

  8. html5--6-47 阶段练习2-渐变按钮

    html5--6-47 阶段练习2-渐变按钮 实例 @charset="UTF-8"; .but1{ padding: 10px 20px; font-size:16px; tex ...

  9. Linux:外网域名防火墙设置导致下载失败

    问题现象: 通过IE从服务器下载文件时,提示Can't read from connection: Connection reset by peer. 别的现场都是好的,只有该现场有这个问题.所以,一 ...

  10. SPOJ:NO GCD (求集合&秒啊)

    You are given N(1<=N<=100000) integers. Each integer is square free(meaning it has no divisor ...