UVA Arif in Dhaka (First Love Part 2) 10294 (polya定理)

来源:互联网 发布:python row函数 编辑:程序博客网 时间:2024/06/05 02:59

Arif in Dhaka (First Love Part 2)

Our hero Arif is now in Dhaka (Look at problem 10244 – First Love if you want to know more aboutArif, but that information is not necessary for this problem. In short, Arif is a brilliant programmerworking at IBM) and he is looking for his first love. Days pass by but his destiny theory is not workinganymore, which means that he is yet to meet his first love. He then decides to roam around Dhaka ona rickshaw (A slow vehicle pulled by human power), running DFS (by physical movement) and BFS(with his eyes) on every corner of the street and market places to increase his probability of reachinghis goal. While roaming around Dhaka he discovers an interesting necklace shop. There he finds someinteresting necklace/bracelet construction sets. He decides to buy some of them, but his programmermind starts looking for other problems. He wants to find out how many different necklace/bracelet canbe made with a certain construction set. You are requested to help him again. The following thingsare true for a necklace/bracelet construction set.a) All necklace/bracelet construction sets has a frame, which has N slots to place N beads.b) All the slots must be filled to make a necklace/bracelet.c) There are t types of beads in a set. N beads of each type are there in the box. So the totalnumber of beads is t · N (t multiplied by N), of which exactly N can be used at a time.Fig. 1: Different types of necklace for t = 2 and different value of NThe figure above shows necklaces for some different values of N (Here, t is always 2). Now let’sturn out attentions to bracelets. A bracelet is a necklace that can be turned over (A junior programmerin Bangladesh says that wrist watch is a necklace (Boys!!! Don’t mind :-))). So for a bracelet thefollowing two arrangements are equivalent. Similarly, all other opposite orientation or mirror imagesare equivalent.So, given the description of a necklace/bracelet construction set you will have to determine howmany different necklace and bracelet can be formed with made with that set

Input

The input file contains several lines of input. Each line contains two positive integers N (0 < N < 51)and t (0 < t < 11) as described in the problem statement. Also note that within this input range inputswill be such that no final result will exceed 11 digits. Input is terminated by end of file.

Output

For each line of input produce one line of output which contains two round numbers NN and NBseparated by a single space, where NN is the number of total possible necklaces and NB is the numberof total possible bracelets for the corresponding input set.

Sample Input

5 2

5 3

5 4

5 5

Sample Output

8 8

51 39

208 136

629 377

//题意:

输入整数n和t,表示用t种颜色n颗珠子,问能制作成的项链和手镯的个数。

HAIT:手镯和项链的区别是手镯可以翻转,而项链不能。

//思路:

用polya定理或者Burnside引理解决,一共有两种置换,即旋转和翻转,项链只有第一种置换,而手镯两种都有。

旋转:当逆时针旋转i个珠子时,则有gcd(i,n)个循环,所以置换的不动点总数为a=t^(gcd(1,n))+t^(gcd(2,n))+......+t^gcd((n,n))。

翻转:有两种情况,第一种是n为奇数时,对称轴有n条,每条对称轴形成(n-1/2)个长度为2的循环和1个长度为1的循环,即(n+1)/2个循环。所以此时的置换不动点

为:b=n*t^((n+1)/2)。

第二种情况是n为偶数时,有两种对称轴,(1)、穿过珠子的对称轴有n/2条,各形成n/2-1个长度为2的循环和两个长度为1的循环;

                                                                   (2)、不穿过珠子的对称轴有n/2条,各形成n/2个长度为2的循环。

所以置换的不动点为b=n/2*(t^(n/2+1)+t^(n.2)).

所以项链的总数为a/n,手镯的个数为(a+b)/(2*n)。

#include<stdio.h>#include<string.h>#include<algorithm>#define INF 0x3f3f3f3f#define ll long long#define N 1010using namespace std;ll p[N];int gcd(int a,int b){return b==0?a:gcd(b,a%b);}int main(){int n,t;int i; while(scanf("%d%d",&n,&t)!=EOF){p[0]=1;for(i=1;i<=n;i++)p[i]=p[i-1]*t;ll a=0;for(i=0;i<n;i++)a+=p[gcd(i,n)];ll b=0;if(n&1)b=n*p[(n+1)/2];elseb=n/2*(p[n/2+1]+p[n/2]);printf("%lld %lld\n",a/n,(a+b)/2/n);}return 0;}


 

 

 

 

 

 

0 0
原创粉丝点击