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 <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
LL P_M( LL a, LL b )
{
LL res=, t=a;
while (b){
if(b&)res*=t;
t*=t;
b>>=;
}
return res;
}
int a[], vi[];
void dfs( int i )
{
if( !vi[i] ){
vi[i]=;
dfs(a[i]);
}
} int find(int t, int n ) // 求循环节 s == gcd( n, t ) ;
{
memset(vi, , sizeof vi);
memset(a, , sizeof a);
for( int i=; i<=n; ++ i ){
int e=(i+t-)%n;
if( e== )e=n;
a[i]=e;
}
int s=;
for( int i=; i<=n; ++ i ){
if(!vi[i]){
dfs(i);
s++;
}
}
return s;
}
int gcd( int x, int y )
{
return y==?x:gcd( y, x%y );
}
int main( )
{
int N;
while( scanf("%d", &N)!= EOF){
if( N==- )break;
if( N== ){puts(""); continue;}
LL ans=;
if( !(N&) ){
ans=P_M(3LL, N);
for( int i=; i<=N; ++i ){
int t=find(i, N);
ans+=P_M( 3LL,t );
}
ans+=(LL)(N/)*(P_M(3LL,(N+)/));
ans+=(LL)(N/)*P_M(3LL,N/);
}
else{
for( int i=; i<N; ++i ){
ans+=P_M(3LL, gcd(i, N));
}
ans+=(LL)(N)*(P_M(3LL,N/+)); }
printf( "%d\n", ans/(*N) );
}
return ;
}
poj 1286
#include <cstdio>
#include <iostream>
using namespace std;
int N, M;
typedef long long LL;
LL P_M(int a, int b )
{
LL res=,t=a;
while(b){
if(b&)res*=t;
t*=t;
b>>=;
}
return res;
}
int gcd( int x, int y )
{
return y==?x:gcd( y, x%y );
}
LL polya( int k, int m )
{
LL ans=;
for( int i=; i<m; ++ i ){
ans+=P_M(k, gcd( i, m ));
}
if( m& ){
ans+=(LL)(m*P_M( k, m/+ ) );
}
else {
ans+=(LL)m/*P_M(k, m/);
ans+=(LL)m/*P_M(k, m/+);
}
if(m)ans/=,ans/=m;
return ans;
}
int main( )
{
while(scanf("%d%d", &N,&M)!=EOF, N+M ){
printf("%lld\n", polya(N, M));
}
return ;
}
poj 2409
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
const LL M=1e9+;
LL P_M(int a, int b )
{
LL res=,t=a;
while(b){
if(b&)res*=t, res%=M;
t*=t, t%=M;
b>>=;
}
return res;
}
int gcd( int x, int y )
{
return y==?x:gcd( y, x%y );
}
LL polya( int k, int m )
{
LL ans=;
for( int i=; i<m; ++ i ){
ans+=P_M(k, gcd( i, m ));
ans%=M;
}
if( m& ){
ans+=(LL)(m*P_M( k, m/+ ) );
}
else {
ans+=(LL)m/*P_M(k, m/);
ans+=(LL)m/*P_M(k, m/+);
}
ans%=M;
return (ans*P_M(*m,M-))%M;// 求逆元
}
int main( )
{
int T, N, K, t=;
scanf("%d", &T);
while(T--){
scanf("%d%d", &N,&K);
printf("Case #%d: %I64d\n", t++, polya(N, K));
}
return ;
}
hdu 3923
poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>的更多相关文章
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- 数学计数原理(Pólya):POJ 1286 Necklace of Beads
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7763 Accepted: 3247 ...
- POJ 1286 Necklace of Beads(项链的珠子)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7874 Accepted: 3290 ...
- POJ 1286 Necklace of Beads(Polya简单应用)
Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...
- 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 1286 Necklace of Beads【polya定理+burnside引理】
和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...
- POJ 1286 Necklace of Beads(Polya原理)
Description Beads of red, blue or green colors are connected together into a circular necklace of n ...
- poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- poj 1286 Necklace of Beads
这是做的第一道群论题,自然要很水又很裸.注意用long long. 就是用到了两个定理 burnside :不等价方案数=每个置换的不动置换方案数的和 / 置换个数 polya: 一个置换的不动置换方 ...
随机推荐
- javaweb学习总结(十八)——JSP属性范围(转)
所谓的属性范围就是一个属性设置之后,可以经过多少个其他页面后仍然可以访问的保存范围. 一.JSP属性范围 JSP中提供了四种属性范围,四种属性范围分别指以下四种: 当前页:一个属性只能在一个页面中取得 ...
- HDU 5890 Eighty seven(DP+bitset优化)
题目链接 Eighty seven 背包(用bitset预处理)然后对于每个询问O(1)回答即可. 预处理的时候背包. #include <bits/stdc++.h> using nam ...
- TreeSet, LinkedHashSet and HashSet 的区别
1. 介绍 TreeSet, LinkedHashSet and HashSet 在java中都是实现Set的数据结构 # TreeSet的主要功能用于排序 # LinkedHashSet的主要功能用 ...
- 实验一 Java实验环境搭建
一 :搭建Java环境 (1)打开IE浏览器,输入网址”https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads ...
- rocketMq---------相关命令
搭建就不详细说了,cent7.x的系统,openJdk8,maven3.x,gradle4.10.2, git 1.8.3.1 直接下载相关的二进制压缩包,解压即用,方便. 下面看常用的管理命令 ro ...
- 在谈MVP之前,你真的懂MVC吗?
最近看到很多文章在谈论MVP或者MVVM模式的,但其实无论MVP还是MVVM都只是MVC模式的一种变种.而如果你对MVC的设计理念都还没有理解透彻,那么即使换成MVP亦或MVVM也不可能让你杂乱不堪的 ...
- 织梦dede如何去除Power by DedeCms
自从dedecms织梦系统更新到6.7日的版本,底部版权信息调用标签{dede:global.cfg_powerby/}会自动加上织梦官方的链接[Power by DedeCms ],想必很多新用户使 ...
- 【Todo】Java学习路线(方向指导)
在网上搜了下Java学习路线(关键词:学习,因为众所周知,实践出牛人,在平时工作不怎么深入的情况下,才强调学习的方向的重要性 ^_^) 发现下面知乎这个回答写的真好.mark如下: https://w ...
- 线性回归,logistic回归分类
学习过程 下面是一个典型的机器学习的过程,首先给出一个输入数据,我们的算法会通过一系列的过程得到一个估计的函数,这个函数有能力对没有见过的新数据给出一个新的估计,也被称为构建一个模型.就如同上面的线性 ...
- PS 如何使用抽出滤镜抠人物的头发丝等细节
1.打开图片,复制背景,关闭背景眼睛.单击 滤镜 -抽出, 我们要学会观察图片,先来看下面这张图: 这张图片色彩虽然不算丰富,但也不是纯色背景,甚至有些许的零乱,但人物的主题却被黑色长发包围, 我们只 ...