<题目链接>

题目大意:
用k种颜色对n个珠子构成的环上色,旋转、翻转后相同的只算一种,求不等价的着色方案数。

解题分析:

对于这种等价计数问题,可以用polay定理来解决,本题是一道polay定理的模板题。

具体polay定理的实现步骤如下(选自算法入门经典训练指南  147页):

#include<iostream>
#include<stdio.h>
using namespace std;
typedef long long LL;
int n, m; int gcd(int a, int b) {
if (b == )return a;
return gcd(b, a % b);
} LL pow(LL a, LL b) { //快速幂
LL ans;
for (ans = ; b; b >>= ) {
if (b & )
ans *= a;
a *= a;
}
return ans;
} int main() {
int i, j;
while (scanf("%d%d", &m, &n) ,n||m)
{
LL ans = ; //旋转的情况
for (i = ; i < n; i++)
ans = ans + pow((LL) m, (LL) gcd(n, i)); //注意这里不用乘以n //翻转的情况
if (n & )
ans += n * pow((LL) m, (LL) n / + ); //若n为奇数,以一个顶点和另外一条边中点的连线为对称轴
else
ans += n / * (pow((LL) m, (LL) n / ) + pow((LL) m, (LL) n / + )); //n为偶数时,以两个顶点连线为对称轴 和 以两个顶点之间的连线为对称轴的情况 printf("%lld\n", ans /(*n)); //(2*n)==n+n(n为奇数)或者是n+(n/2+n/2)
}
return ;
}

2018-08-11

POJ 2409 Let it Bead【Polya定理】(模板题)的更多相关文章

  1. POJ 2409 Let it Bead (Polya定理)

    题意 用k种颜色对n个珠子构成的环上色,旋转翻转后相同的只算一种,求不等价的着色方案数. 思路 Polya定理 X是对象集合{1, 2, --, n}, 设G是X上的置换群,用M种颜色染N种对象,则不 ...

  2. poj 2409 Let it Bead Polya计数

    旋转能够分为n种置换,相应的循环个数各自是gcd(n,i),个i=0时不动,有n个 翻转分为奇偶讨论,奇数时有n种置换,每种有n/2+1个 偶数时有n种置换,一半是n/2+1个,一半是n/2个 啃论文 ...

  3. [ACM] POJ 2409 Let it Bead (Polya计数)

    参考:https://blog.csdn.net/sr_19930829/article/details/38108871 #include <iostream> #include < ...

  4. bzoj 1004 Cards & poj 2409 Let it Bead —— 置换群

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 关于置换群:https://www.cnblogs.com/nietzsche-oie ...

  5. poj 1286 Necklace of Beads &amp; poj 2409 Let it Bead(初涉polya定理)

    http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...

  6. POJ 2409 Let it Bead:置换群 Polya定理

    题目链接:http://poj.org/problem?id=2409 题意: 有一串n个珠子穿起来的项链,你有k种颜色来给每一个珠子染色. 问你染色后有多少种不同的项链. 注:“不同”的概念是指无论 ...

  7. POJ 2409 Let it Bead(Polya定理)

    点我看题目 题意 :给你c种颜色的n个珠子,问你可以组成多少种形式. 思路 :polya定理的应用,与1286差不多一样,代码一改就可以交....POJ 1286题解 #include <std ...

  8. poj 2409 Let it Bead【polya定理+burnside引理】

    两种置换 旋转:有n种,分别是旋转1个2个--n个,旋转i的循环节数位gcd(i,n) 翻转:分奇偶,对于奇数个,只有一个珠子对一条边的中点,循环节数为n/2+1:对于偶数个,有珠子对珠子和边对边,循 ...

  9. POJ 2409 Let it Bead(polya裸题)

    题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...

随机推荐

  1. resolution will not be reattempted until the update interval of repository-group has elapsed or updates are forced

    Failed to execute goal on project safetan-web: Could not resolve dependencies for project com.safeta ...

  2. MHA-手动Failover流程(传统复制&GTID复制)

    本文仅梳理手动Failover流程.MHA的介绍详见:MySQL高可用架构之MHA 一.基本环境 1.1.复制结构 VMware10.0+CentOS6.9+MySQL5.7.21 ROLE HOST ...

  3. mysql 5.7 ~ 新特性

    mysql 5.7特性 简介:mysql 5.7内存和线程性能方面的优化一 细节优化 参数:  1 innodb_buffer_pool    改进 innodb_buffer_pool可以动态扩大, ...

  4. GCC编译过程与动态链接库和静态链接库

    1. 库的介绍 库是写好的现有的,成熟的,可以复用的代码.现实中每个程序都要依赖很多基础的底层库,不可能每个人的代码都从零开始,因此库的存在意义非同寻常. 本质上来说库是一种可执行代码的二进制形式,可 ...

  5. KERMIT,XMODEM,YMODEM,ZMODEM传输协议小结

    转:http://blog.163.com/czblaze_3333/blog/static/208996228201272295236713/ Kermit协议 报文格式: 1.       MAR ...

  6. [Shell]获取IP地址

    ifconfig eth0 | grep "inet addr:" | awk '{print $2}' | cut -c 6- ifconfig eth1 | grep &quo ...

  7. bzoj 1803: Spoj1487 Query on a tree III(主席树)

    题意 你被给定一棵带点权的n个点的有根数,点从1到n编号. 定义查询 query(x,k): 寻找以x为根的k大点的编号(从小到大排序第k个点) 假设没有两个相同的点权. 输入格式: 第一行为整数n, ...

  8. zabbix系列(四)Zabbix3.0.4添加对Nginx服务的监控

    Zabbix3.0.4添加对Nginx服务的监控 通过Nginx的http_stub_status_module模块提供的状态信息来监控,所以在Agent端需要配置Nginx状态获取的脚本,和添加ke ...

  9. 【前端】三个bug

    目录 一.Array对象的indexOf() 二.使用jquery,clone()下拉框问题 三.jquery获取获取html5的data-*属性 一.Array对象的indexOf() 1.inde ...

  10. h5之js生成二维码

    目录架构: index.html <!DOCTYPE> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang=& ...