POJ 题目1286 Necklace of Beads(Polya定理) -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

    Necklace of BeadsTime Limit:1000MSMemory Limit:10000KTotal Submissions:7061Accepted:2942

    Description

Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are produced by rotation around the center of the circular necklace or reflection to the axis of symmetry are all neglected, how many different forms of the necklace are there?

    Input

The input has several lines, and each line contains the input data n.

    -1 denotes the end of the input file.

    Output

The output should contain the output data: Number of different forms, in each line correspondent to the input data.

    Sample Input

45-1

    Sample Output

2139

    Source

    Xi'an 2002

    题目大意:

    n个珠子串成一个圆,用三种颜色去涂色,

POJ 题目1286 Necklace of Beads(Polya定理)

电脑资料

POJ 题目1286 Necklace of Beads(Polya定理)》(https://www.unjs.com)。问一共有多少种不同的涂色方法。

    不同的涂色方法被定义为:如果这种涂色情况翻转,旋转不与其他情况相同就为不同。

    解题思路:

    Polya定理模版题。

    对于顺时针长度为i的旋转,为pow(3,__gcd(n,i);

    对于翻转,当为奇数时,有:n*pow(3.0,n/2+1);

    当为偶数时,有:n/2*pow(3.0,n/2)+n/2*pow(3.0,n/2+1);

    一共有2*n种情况,最后要除以2*n

    ac代码

#include<stdio.h>#include<stdlib.h>#include<math.h>int gcd(int a,int b){	if(a<b></p></b)></math.h></stdlib.h></stdio.h>

最新文章