UVa10294
来源:互联网 发布:吉祥网络投票公司 编辑:程序博客网 时间:2024/05/19 17:11
UVa10294 - 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.
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.
题目大意:n个珠子的项链,染t种颜色
输出只能旋转的方案数和还能翻转的方案数。
解:这道题是polya的裸体
定理前提:
(1)定义置换f是一个对C的置换
(2)定义置换群G
(3)定义群作用“。”,并诱导出群等价关系“~”
(4)由(1)(2)(3),我们得出找G中置换的方法:使旋转和翻转意义下本质相同的着色在置换群G的作用下保持等价关系
(5)Burnside引理:P = 1/|G|∑|S(g)|
其中S(g)为C中对置换g保持不变的着色集合。
polya计数定理
设G是集合X上的一个置换群,X中每个元素可以被染成k种颜色,则不等价的着色数为:P = 1/|G|∑k^nc(g)
其中nc(g)为置换g中循环节的个数。
对这道题,旋转的循环节个数为:对位置1—>s的珠子,这个置换的循环节个数为gcd(n,s-1)
翻转的循环节个数为:
(1)n & 1 = 1: n / 2 + 1
(2)n & 1 = 0: [(n-2) / 2 + 2] 和 n / 2
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;typedef long long LL;LL p[100];LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b);}int main(){ int n, t; while (~scanf("%d%d", &n, &t)) { p[0] = 1; for (int i = 1; i <= n; i++) p[i] = p[i-1] * t; LL sum = 0, G = n; for (int i = 1; i <= n; i++) sum += p[gcd(n, i-1)]; printf("%lld ", sum / G); if (n & 1) sum += n * p[(n >> 1) + 1], G += n; else sum += n * (p[(n-2)/2+2] + p[n/2])/2, G += n; printf("%lld\n", sum / G); }}
- UVa10294
- uva10294(置换群)
- Uva10294 Arif in Dhaka (置换问题)
- 【HDU3923】类似uva10294项链种类polya计数+逆元
- UVA10294项链和手镯(等价类计数问题)
- uva10294 Arif in Dhaka(置换的等价类计数)
- uva10294 Arif in Dhaka (First Love Part 2)
- 在Mac中配置Jenkins和Maven项目遇到的问题
- PAT乙级1072. 开学寄语(20)
- 循环
- 一道区间dp和一道字符串
- HH的项链(树状数组)区间内不同的数量
- UVa10294
- 前端工程师应该具备的能力
- 1008 Elevator(20)
- 回顾大一·C语言编程14.1+14.2(1)(2)+14.3
- java获取和设置系统变量(环境变量)
- HashMap实现原理分析
- 服务治理(一)
- 安装cnpm
- MFC日期时间拾取控件和月历控件