POJ 2409 Let it Bead(polay计数)
题目链接:http://poj.org/problem?id=2409
题意:给出一个长度为m的项链,每个珠子可以用n种颜色涂色。翻转和旋转后相同的算作一种。有多少种不同的项链?
思路:
(1)
对于Burnside引理,G为所有置换集合,|G|为所有置换个数,gi为第i种置换,D(gi)为在第i种置换下保持不动的元素个数。
对于Polay定理,G为所有置换集合,|G|为所有置换个数,gi为第i种置换,n为颜色的种类,c(gi)为第i种置换的循环节个数。
(2)对于Polay,一般解题步骤:确定循环群;计算每种循环下的循环节个数。
对于本题,旋转可以分为旋转i=0,1,2,……m-1个,循环节个数为Gcd(m,i)。对于翻转,若m为奇数,只有通过一顶点和其对边中点的轴翻转,循环节m/2+1;对于m为偶数,两种翻转的轴,第一是两个顶点的连线,循环节m/2+1,第二是对边中点的连线,循环节m/2。
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <map>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define Len(x) x.length()
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define FOR0(i,x) for(i=0;i<x;i++)
#define FOR1(i,x) for(i=1;i<=x;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FORL0(i,a) for(i=a;i>=0;i--)
#define FORL1(i,a) for(i=a;i>=1;i--)
#define FORL(i,a,b)for(i=a;i>=b;i--)
#define rush() int CC;for(scanf("%d",&CC);CC--;)
#define Rush(n) while(scanf("%d",&n)!=-1)
using namespace std;
void RD(int &x){scanf("%d",&x);}
void RD(i64 &x){scanf("%I64d",&x);}
void RD(u64 &x){scanf("%I64u",&x);}
void RD(u32 &x){scanf("%u",&x);}
void RD(double &x){scanf("%lf",&x);}
void RD(int &x,int &y){scanf("%d%d",&x,&y);}
void RD(i64 &x,i64 &y){scanf("%I64d%I64d",&x,&y);}
void RD(u32 &x,u32 &y){scanf("%u%u",&x,&y);}
void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}
void RD(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void RD(i64 &x,i64 &y,i64 &z){scanf("%I64d%I64d%I64d",&x,&y,&z);}
void RD(u32 &x,u32 &y,u32 &z){scanf("%u%u%u",&x,&y,&z);}
void RD(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void RD(char &x){x=getchar();}
void RD(char *s){scanf("%s",s);}
void RD(string &s){cin>>s;}
void PR(int x) {printf("%d\n",x);}
void PR(int x,int y) {printf("%d %d\n",x,y);}
void PR(i64 x) {printf("%lld\n",x);}
void PR(u32 x) {printf("%u\n",x);}
void PR(u64 x) {printf("%I64u\n",x);}
void PR(double x) {printf("%.10lf\n",x);}
void PR(char x) {printf("%c\n",x);}
void PR(char *x) {printf("%s\n",x);}
void PR(string x) {cout<<x<<endl;}
const i64 inf=((i64)1)<<60;
const int mod=10007;
const double dinf=1e50;
const int INF=1000000000;
const int N=55;
int n,m;
int Gcd(int x,int y)
{
if(!y) return x;
return Gcd(y,x%y);
}
int Pow(int x,int y)
{
int ans=1;
while(y)
{
if(y&1) ans*=x;
x=x*x;
y>>=1;
}
return ans;
}
int main()
{
Rush(n)
{
RD(m);
if(!n&&!m) break;
int ans=0,i;
FOR0(i,m) ans+=Pow(n,Gcd(m,i));
if(m&1) ans+=m*Pow(n,m/2+1);
else ans+=m/2*Pow(n,m/2)+m/2*Pow(n,m/2+1);
ans/=(2*m);
PR(ans);
}
return 0;
}
POJ 2409 Let it Bead(polay计数)的更多相关文章
- [ACM] POJ 2409 Let it Bead (Polya计数)
参考:https://blog.csdn.net/sr_19930829/article/details/38108871 #include <iostream> #include < ...
- poj 2409 Let it Bead Polya计数
旋转能够分为n种置换,相应的循环个数各自是gcd(n,i),个i=0时不动,有n个 翻转分为奇偶讨论,奇数时有n种置换,每种有n/2+1个 偶数时有n种置换,一半是n/2+1个,一半是n/2个 啃论文 ...
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- bzoj 1004 [HNOI2008]Cards && poj 2409 Let it Bead ——置换群
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 http://poj.org/problem?id=2409 学习材料:https:/ ...
- poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>
链接:http://poj.org/problem?id=1286 http://poj.org/problem?id=2409 #include <cstdio> #include &l ...
- POJ 2409 Let it Bead 组合数学
题目地址: http://poj.org/problem?id=2409 给你一串珠子有m个,用n种不同的颜色涂色,问有多少种分法. 用polay定理求解,对于排成一排的带编号的小球,按照某一种方案改 ...
- POJ 2409 Let it Bead(polya裸题)
题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...
- poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)
题目:http://poj.org/problem?id=2409 题意:用k种不同的颜色给长度为n的项链染色 网上大神的题解: 1.旋转置换:一个有n个旋转置换,依次为旋转0,1,2,```n-1. ...
- POJ 2409 Let it Bead:置换群 Polya定理
题目链接:http://poj.org/problem?id=2409 题意: 有一串n个珠子穿起来的项链,你有k种颜色来给每一个珠子染色. 问你染色后有多少种不同的项链. 注:“不同”的概念是指无论 ...
随机推荐
- verilogHDL设计中的同步时序逻辑
引用自夏宇闻教授 1.同步时序逻辑: 是指表示状态的寄存器组的值只能在唯一确定的触发条件发生改变. 只能由时钟的正跳变沿或者负跳变沿触发的状态机就是一例,always@(posedge clk). 1 ...
- POJ 2315 最小费用最大流
从1走到N然后从N走回来的最短路程是多少? 转换为费用流来建模. 1: /** 2: 因为e ==0 所以 pe[v] pe[v]^1 是两条相对应的边 3: E[pe[v]].c -= aug; E ...
- 只是一个用EF写的一个简单的分页方法而已
只是一个用EF写的一个简单的分页方法而已 慢慢的写吧.比如,第一步,先把所有数据查询出来吧. //第一步. public IQueryable<UserInfo> LoadPagesFor ...
- android studio出现 waiting for adb
cmd进入命令行,进入adb所在的目录下: 出现的鬼异问题如下. C:\Users\xxxx>adb start-server adb server is out of date. killin ...
- Text selection in div(contenteditable) when double click
背景: 在最近项目中,碰到一个问题:有一个可编辑的div需要双击时可编辑,blur或者回车时将编辑结果保存.你可能注意到双击时,文字会被选中,可编辑区域不会focus到光标位置.考虑到兼容性问题,写了 ...
- System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本
问题描述: c#程序本机运行没有问题,部署到正式环境后报错: System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本 思考: 难道真是客户端的问题吗? ...
- [问题]C# 结构体对齐:如何将变长byte数组对齐
[StructLayout(LayoutKind.Sequential,Pack=1)] struct Report_Read_Parameter { byte Confirmation; byte ...
- CSS3属性box-shadow使用教程,css3box-shadow
CSS3的box-shadow属性可以让我们轻松实现图层阴影效果.我们来实战详解一下这个属性. 1. box-shadow属性的浏览器兼容性先来看一个这个属性的浏览器兼容性: Opera: 不知道是从 ...
- JavaScript高级---组合模式设计
一.设计模式 javascript里面给我们提供了很多种设计模式: 工厂.桥.组合.门面.适配器.装饰者.享元.代理.观察者.命令.责任链 在前面我们实现了工厂模式和桥模式 工厂模式 : 核心:为了生 ...
- UVALive 6525
二分图最大匹配 #include<cstdio> #include<iostream> #include<cstring> #define MAX 10010 us ...