UVA 10294 Arif in Dhaka (First Love Part 2) Polya计数

题目链接

Polya计数入门题


10294 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 about

Arif, but that information is not necessary for this problem. In short, Arif is a brilliant programmer

working at IBM) and he is looking for his first love. Days pass by but his destiny theory is not working

anymore, which means that he is yet to meet his first love. He then decides to roam around Dhaka on

a 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 reaching

his goal. While roaming around Dhaka he discovers an interesting necklace shop. There he finds some

interesting necklace/bracelet construction sets. He decides to buy some of them, but his programmer

mind starts looking for other problems. He wants to find out how many different necklace/bracelet can

be made with a certain construction set. You are requested to help him again. The following things

are 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 total

number 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 N

The figure above shows necklaces for some different values of N (Here, t is always 2). Now let’s

turn out attentions to bracelets. A bracelet is a necklace that can be turned over (A junior programmer

in Bangladesh says that wrist watch is a necklace (Boys!!! Don’t mind :-))). So for a bracelet the

following two arrangements are equivalent. Similarly, all other opposite orientation or mirror images

are equivalent.

Universidad de Valladolid OJ: 10294 – Arif in Dhaka (First Love Part 2) 2/2

So, given the description of a necklace/bracelet construction set you will have to determine how

many 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 inputs

will 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 NB

separated by a single space, where NN is the number of total possible necklaces and NB is the number

of 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

/* ***********************************************
Author        :CKboss
Created Time  :2015年05月06日 星期三 15时32分53秒
File Name     :UVA10294.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long int LL;

LL n,t;
LL Pow[60];

LL gcd(LL a,LL b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%lld%lld",&n,&t)!=EOF)
    {

        Pow[0]=1LL;
        for(int i=1;i<=n+3;i++) Pow[i]=Pow[i-1]*t;

        LL a=0LL,b=0LL;
        for(LL i=0;i<n;i++) a+=Pow[gcd(n,i)];

        if(n%2==0)
        {
            b=(n/2)*(Pow[n/2]+Pow[n/2+1]);
        }
        else
        {
            b=n*Pow[(n+1)/2];
        }

        printf("%lld %lld\n",a/n,(a+b)/2/n);
    }

    return 0;
}
时间: 2024-10-12 21:03:55

UVA 10294 Arif in Dhaka (First Love Part 2) Polya计数的相关文章

UVa 10294 Arif in Dhaka (First Love Part 2) Polya定理

题目来源:UVa 10294 Arif in Dhaka (First Love Part 2) 题意:n颗珠子t种颜色 求有多少种项链和手镯 项链不可以翻转 手镯可以翻转 思路:Polya定理  题目就是求等价类 项链只能旋转 手镯可以旋转也可以翻转 根据定理 等价类的数量等于各个置换f的t^m(f)的平均数 m(f)是置换的循环节数 下面每次t^x x都是循环节数 下面考虑手镯 旋转翻转都算 对于旋转 可以旋转0,1,...,n-1 每一个置换的循环节为gcd(0,n), gcd(1,n),

uva 10294 - Arif in Dhaka (First Love Part 2)(置换)

题目链接:uva 10294 - Arif in Dhaka (First Love Part 2) 题目大意:项链和手镯都是由若珠子穿成的环形首饰,区别在于手镯可以翻转,但是项链不行.给定n和t,表示用t种颜色的n个珠子能制作的项链和手镯的个数. 解题思路:等价类计数,一共两种置换,旋转或者翻转. 旋转:枚举间距0,1,2,3-,n?1,所以不动点a=∑i=0n?1tgcd(n,i) 翻转:当n为奇数时,对称轴有n条,每条对称轴形成n?12个长度为2的循环和一个长度为1的循环,所以不动点b1=

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

Description Problem L Arif in Dhaka (First Love Part 2) Input: standard input Output: standard output Time Limit: 2 seconds Our hero Arif is now in Dhaka (Look at problem 10244 – First Love if you want to know more about Arif, but that information is

UVA 10294 Arif in Dhaka (置换polya)

[题目链接]:click here~~ [题目大意]: 给你一串珠子(连接成了一个环),共有n个珠子组成,你有t种颜色,现在你来给这个珠子染色,问染成项链有多少种方法?染成手镯有多少种方法?在项链里,经过顺时针旋转后相同的算一个,在手镯里,经过顺时针旋转或者沿着对称轴兑换后一样的算一个.即不同之处在于项链不能够反转,而手镯可以反转. [思路]: 首先,我们来看看两个很有用的关于置换的定理,第一个就是Burnside 描述为:对于置换f,一种着色方案s经过一种置换后不变,则称这种着色方案s是f的不

10294 - Arif in Dhaka (First Love Part 2) (数论置换)

UVA 10294 - Arif in Dhaka (First Love Part 2) 题目链接 题意:给定n个珠子,t种颜色, 问能组成几个项链和手镯(手镯能翻转,项链不能) 思路:利用Burnside求解,推理出旋转的循环个数是gcd(i, n),翻转的分为奇偶情况考虑 代码: #include <stdio.h> #include <string.h> const int N = 30; int t, next[N], vis[N], num[N]; char str[N

UVa 10294 (P&#243;lya计数) Arif in Dhaka (First Love Part 2)

Burnside定理:若一个着色方案s经过置换f后不变,称s为f的不动点,将置换f的不动点的数目记作C(f).等价类的数目等于所有C(f)的平均值. 一个项链,一个手镯,区别在于一个能翻转一个不能,用t种颜色染n颗珠子,求等价类的个数. 旋转置换群一共有n个置换,分别对应将项链整体逆时针旋转0个.1个.2个...珠子的置换. 对于第i个置换,第0个.i个.2i...个珠子构成一个循环,共有gcd(n, i)个循环,每个循环中有n / gcd(n, i)个珠子. 所以n个置换,每个置换的不动点有t

UVA 10294 等价类计数

题目大意: 项链和手镯都是若干珠子穿成的环形首饰,手镯可以旋转和翻转,但项链只能旋转,给n个珠子,t种颜色,求最后能形成的手镯,项链的数量 这里根据等价类计数的polya定理求解 对于一个置换f,若一种方案经过置换后不改变,那么不改变的点的个数记作C(f) 统计所有的C(f) , 相加之后求和除以置换的种数即可 那么这道题里面 对于项链来说,旋转一个角度,也就是2*PI/n , 那么置换群可表示为 1 2 3 4 .... n 2 3 4 5 ... 1 这里就存在一个循环节 所以方案数为 t^

uva 10294

数目n,颜色t,项链旋转,手镯旋转且翻转,问各有多少种? #include <iostream> #include <cstdio> using namespace std; #define maxn 55 #define LL long long int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } LL p[maxn]; int n, t; int main() { while(~scanf("

UVA10294 Arif in Dhaka (First Love Part 2)

本文是刘汝佳<算法竞赛入门经典--训练指南>的读书笔记. 解题思路: 对于项链,它只支持旋转置换:而手镯支持旋转和翻转.下面由这两种置换来研究本题. 旋转 设顺时针旋转 \(i\) 颗珠子的间距,则珠子 \(0, i, 2i, ...\) 构成一个循环. 设每个循环有 \(t\) 颗珠子,则这 \(t\) 颗珠子的编号分别为:\(0, (i \mod n), (2i \mod n), ... [(t-1)i \mod n]\),我们不能推出:\(ti \mod n = 0\),即 \(ti =