UVA10733 The Colored Cubes【Polya定理】

All 6 sides of a cube are to be coated with paint. Each side is is coated uniformly with one color. When a selection of n different colors of paint is available, how many different cubes can you make?
    Note that any two cubes are only to be called “different” if it is not possible to rotate the one into such a position that it appears with the same coloring as the other.
Input
Each line of the input file contains a single integer n (0 < n < 1000) denoting the number of different colors. Input is terminated by a line where the value of n = 0. This line should not be processed.
Output
For each line of input produce one line of output. This line should contain the number of different cubes that can be made by using the according number of colors.
Sample Input
1
2
0
Sample Output
1
10

问题链接UVA10733 The Colored Cubes
问题简述:一个立方体,n种颜色,问能涂成多少不同立方体?
问题分析:用Ploya定理来解决。正方体右24种不同的旋转方向。
程序说明:功能封装到函数。阶乘次数太少,没有必要用快速幂。用inline修饰词来加速。
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10733 The Colored Cubes */

#include <bits/stdc++.h>

typedef long long LL;

inline LL pow(int n, int k)
{
    LL ret = 1;
    for(int i = 1; i <= k; i++)
        ret *= n;
    return ret;
}

inline LL polya(int n)
{
    LL sum = 0;
    sum += pow(n, 6) + 3 * pow(n, 4) + 12 * pow(n, 3) + 8 * pow(n, 2);
    return sum;
}

int main()
{
    int n;
    while(~scanf("%d", &n) && n)
        printf("%lld\n", polya(n) / 24);

    return 0;
}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页