POJ1286,2409——Let it Bead,Necklace of Beads( Pólya定理)

Necklace of Beads
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 5737 Accepted: 2367
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
4
5
-1
Sample Output
21
39
Source
Xi'an 2002


Let it Bead
Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 3802
Accepted: 2477
Description
"Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets. However, over 90 percent of the target audience insists that the bracelets be unique. (Just imagine what happened if two women showed up at the same party wearing identical bracelets!) It's a good thing that bracelets can have different lengths and need not be made of beads of one color. Help the boss estimating maximum profit by calculating how many different bracelets can be produced. 

A bracelet is a ring-like sequence of s beads each of which can have one of c distinct colors. The ring is closed, i.e. has no beginning or end, and has no direction. Assume an unlimited supply of beads of each color. For different values of s and c, calculate the number of different bracelets that can be made.
Input
Every line of the input file defines a test case and contains two integers: the number of available colors c followed by the length of the bracelets s. Input is terminated by c=s=0. Otherwise, both are positive, and, due to technical difficulties in the bracelet-fabrication-machine, cs<=32, i.e. their product does not exceed 32.
Output
For each test case output on a single line the number of unique bracelets. The figure below shows the 8 different bracelets that can be made with 2 colors and 5 beads.
Sample Input                                                                                                                                                
1 1
2 1
2 2
5 1
2 5
2 6
6 2
0 0
Sample Output
1
2
3
5
8
13
21
Source
Ulm Local 2000

解析:

         这两道题都是很裸的polya定理题,而且代码几乎一样,所以把他们放到一起。。。

         至于polya定理的理论部分,可以看我的上一篇blog。。。

         这两道题:

         对于旋转的情况:共有n个置换,其中旋转k个位置的置换的循环节数为gcd(n,k)。——(|)证明如下
         对于翻转的情况:若n为奇数,则对称轴过一顶点和一边中点,n种置换,循环节长度n/2+1;若n为偶数,对称轴有两种,过两点和过两边中点,两者各有n/2种置换,前者          循环节长度为n/2+1,后者为n/2。

         总共有2*n个置换。

         这部分也很好理解。。。接下来我要来证明一下(|)。。。

          假设旋转k个位置,因为polya定理要求在置换后元素不变的情况下每种置换的循环节数,所以当他旋转到他原来的位置时,

          所经过的点数既是n的倍数,又是k的倍数,且是n和k的最小公倍数,即lcm(n,k);

          因为每次旋k个位置,所以当前置换中循环的个数为lcm(n,k)/k;

          所以每个置换的循环节数=n/(lcm(n,k)/k)=gcd(n,k)。

代码:

poj1286

#include<cstdio>
#include<cmath>
using namespace std;
int n;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}

int polya(int n)
{
    if(n==0)return 0;
    double ans=0;
    for(int i=1;i<=n;i++)ans+=pow(3.0,gcd(n,i));
    if(n&1)ans+=n*pow(3.0,n/2+1);
    else ans+=n/2*(pow(3.0,n/2)+pow(3.0,n/2+1));
    return ans/(2*n);
}

int main()
{
    freopen("poj1286.in","r",stdin);
    freopen("poj1286.out","w",stdout);
    while(scanf("%d",&n))
    {
        if(n==-1)break;
        printf("%d\n",polya(n));
    }
    return 0;
}
poj2409

#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m;

int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}

int polya(int n,int m)
{
    int ans=0,i;
    for(i=1;i<=n;i++)ans+=pow(m*1.0,gcd(n,i));
    if(n&1)ans+=n*pow(m*1.0,n/2+1);
    else ans+=n/2*(pow(m*1.0,(n/2+1))+pow(m*1.0,n/2*1.0));
    return ans/(2*n);
}

int main()
{
    freopen("poj2409.in","r",stdin);
    freopen("poj2409.out","w",stdout);
    while(scanf("%d%d",&m,&n)&&n&&m)printf("%d\n",polya(n,m));
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值