hdu 1220 Cube (组合数学)

/*
给你一个边长n的正方体,切割成n*n*n个单位体积的小正方体,求所有公共顶点数<=2的小正方体的对数。
公共点的数目可能有:0,1,2,4.
我们用总的对数减掉有四个公共点的对数就可以了。

总的对数:n^3*(n^3-1)/2(一共有n^3块小方块,从中选出2块)

而4个交点的立方体对是两个立方体共面的情况,
所以我们只要求出大的立方体一共有多少个单位面积的公共面就可以了,
既所有单位立方体的面数6*n^3减去在大立方体表面的面数6*n^2就可以了,,

所以结果为:n^3 * (n^3-1) / 2 - 3*n^2(n-1)
*/
# include <stdio.h>
# include <algorithm>
# include <string.h>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        printf("%d\n",(n*n*n*(n*n*n-1))/2-3*n*n*(n-1));
    }
    return 0;
}

时间: 2024-10-14 05:02:08

hdu 1220 Cube (组合数学)的相关文章

题解报告:hdu 1220 Cube

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1220 问题描述 Cowl擅长解决数学问题. 有一天,一位朋友问他这样一个问题:给你一个边长为N的立方体,它被与其侧面平行的平面切割成N * N * N个单位立方体. 两个单位立方体可能没有共同点或两个共同点或四个共同点. 你的工作是计算有多少对不超过两个公共点的单位立方体.处理到文件的结尾. 输入 会有很多测试用例. 每个测试用例只会在一行中给出一个立方体的边长N. N是正整数(1 <= N <=

HDU(1220)——Cube

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 cub

hdu 1220 Cube 简单数论

Cube Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1516    Accepted Submission(s): 1206 Problem Description Cowl is good at solving math problems. One day a friend asked him such a question:

HDU 1221: Cube

HDU 1221: Cube ///@author Sycamore, ZJNU ///@accepted_on 2017-01-24 #include<iostream> using namespace std; int main() { int N; while (cin >> N) cout << N*N*N *(N*N*N - 1) / 2 - 3 * (N - 1)*N*N << endl; return 0; }

HDU - 3584 Cube (三维树状数组 + 区间改动 + 单点求值)

HDU - 3584 Cube Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the number in the i-th row , j-th column and k-th layer. I

HDU 3584 Cube (三维 树状数组)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3584 Cube Problem Description Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the number in the i-th row , j-th column and k-th layer. Initially we have A[i, j, k] = 0 (1 <= i, 

HDU - 3584 Cube (三维树状数组 + 区间修改 + 单点求值)

HDU - 3584 Cube Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the number in the i-th row , j-th column and k-th layer. I

hdu 4670 Cube number on a tree(点分治)

Cube number on a tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1628    Accepted Submission(s): 382 Problem Description The country Tom living in is famous for traveling. Every year, man

HDU 1988 Cube Stacking (数据结构-并查集)

Cube Stacking Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 18900   Accepted: 6568 Case Time Limit: 1000MS Description Farmer John and Betsy are playing a game with N (1 <= N <= 30,000)identical cubes labeled 1 through N. They start w