polya

来源:互联网 发布:电视盒桌面软件 编辑:程序博客网 时间:2024/05/22 15:38

1/|G| {m^c(a1)+m^c(a2)+m^c(a3)+...+m^c(ag)}

其中c(ai)为置换ai的循环节数(i = 1,2,...g)。

m种颜色的珠子,每种颜色珠子个数不限,将这些珠子做成长度为n的项链,问能做成多少种不重复的项链。两条项链相同,当且仅当两条项链通过旋转或者翻转后能重合在一起,且对应珠子的颜色相同。

(1)旋转:将项链顺时针旋转i格后,其循环节数为gcd(n,i);

(2)翻转:

1.当n为奇数时,共有n个循环节数为(n+1)/2的循环群。

2.当n为偶数时,共有n/2个循环节数为(n+2)/2的循环群,和n/2个循环节数为n/2的循环群。

poj 1286 Necklace of Beads

#include <iostream>#include <algorithm>#include <string.h>#include <stdio.h>#include <math.h>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#define LL long longusing namespace std;int main(){    int n;    while(scanf("%d",&n),n!=-1){        if(n <= 0){            printf("0\n");continue;        }        LL sum = 0;        for(int i = 1; i <= n; ++i){            int d = __gcd(n,i);            sum += (LL)pow(3.0,d*1.0);        }        if(n&1){            sum += (LL)(n*pow(3.0,(n+1)/2.0));        }        else{            sum += (LL)((n/2)*pow(3.0,(n+2)/2.0));            sum += (LL)((n/2)*pow(3.0,(n/2.0)));        }        sum /= (LL)(2*n);        printf("%lld\n",sum);    }        return 0;}

poj 2409 Let it Bead

#include <iostream>#include <algorithm>#include <string.h>#include <stdio.h>#include <math.h>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#define LL long longusing namespace std;int main(){    int n,m;    while(scanf("%d%d",&m,&n),n|m){                LL sum = 0;        for(int i = 1; i <= n; ++i){            int d = __gcd(n,i);            sum += (LL)pow(m*1.0,d*1.0);        }        if(n&1){            sum += (LL)(n*pow(m*1.0,(n+1)/2.0));        }        else{            sum += (LL)((n/2)*pow(m*1.0,(n+2)/2.0));            sum += (LL)((n/2)*pow(m*1.0,(n/2.0)));        }        sum /= (LL)(2*n);        printf("%lld\n",sum);    }        return 0;}


0 0
原创粉丝点击