http://poj.org/problem?id=1286

题意:求用3种颜色给n个珠子涂色的方案数。polya定理模板题。

 #include <stdio.h>
#include <math.h> long long gcd(long long a,long long b)
{
return b?gcd(b,a%b):a;
}
int main()
{
long long n;
while(~scanf("%lld",&n))
{
if (n==-)
break;
if (n <= )
{
printf("0\n");
continue;
}
long long ans = ;
for (int i = ; i < n; i++)
{
ans+=pow(,gcd(i,n));
}
if (n&)
ans+=n*pow(,n/+);
else
{
ans+=n/*pow(,n/)+n/*pow(,n/+);
}
printf("%lld\n",ans/n/);
}
return ;
}

同类型的题:

 Let it Bead

http://poj.org/problem?id=2409

 #include <stdio.h>
#include <math.h>
long long gcd(long long a,long long b)
{
return b?gcd(b,a%b):a;
}
/*long long pow(long long a,long long b)
{
long long res = 1;
while(b)
{
if (b&1)
res*=a;
a*=a;
b>>=1;
}
return res;
}*/
int main()
{
int n,k;
while(~scanf("%d%d",&k,&n))
{
if (k==&&n==)
break;
long long ans = ;
for (int i = ; i < n; i++)
{
ans+=pow(k,gcd(i,n));
}
if (n&)
ans+=n*pow(k,n/+);
else
{
ans+=n/*pow(k,n/)+n/*pow(k,n/+);
}
printf("%lld\n",ans/n/);
}
return ;
}

Necklace of Beads(polya定理)的更多相关文章

  1. poj1286 Necklace of Beads—— Polya定理

    题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...

  2. POJ1286 Necklace of Beads(Polya定理)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9359   Accepted: 3862 Description Beads ...

  3. poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)

      Description Beads of red, blue or green colors are connected together into a circular necklace of ...

  4. Necklace of Beads(polya计数)

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7451   Accepted: 3102 ...

  5. hdu 1817 Necklace of Beads (polya)

    Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. Necklace of Beads (polya定理的引用)

    Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n &l ...

  7. hdu 1817 Necklace of Beads(Polya定理)

    Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. POJ 1286 Necklace of Beads(Polya定理)

    点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...

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

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

随机推荐

  1. CentOS7阿里云服务器,python程序requests无法正常post网站(报502)

    问题描述: 使用jenkins构建接口自动化测试时,发现新增加的接口case不能访问通,会报502错误(本地可以跑通,在测试服就会502)解决的思路: 缩小调试范围(去掉jenkins db环境,将问 ...

  2. LINUX -- pthread_detach()与pthread_join()

    pthread_detach()即主线程与子线程分离,子线程结束后,资源自动回收. int pthread_join(pthread_t tid, void **thread_return); {su ...

  3. Linux - docker基础

    目录 Linux - docker基础 docker的概念 docker安装流程 docker基本命令学习 docker 的 hello docker 运行一个ubuntu容器 Docker与Cent ...

  4. copy the content of a file muliptle times and save as ordered files:

    input: transient.case outputs: transient_1.case, transient_2.case,...transient_101.case ********** n ...

  5. 微信小程序如何引用iconfont图标

    最近在研究微信小程序,自己写demo的时候想要引用巴里巴巴图标库的图标,于是: @font-face { font-family: 'iconfont'; src: url('iconfont.eot ...

  6. 【Mail.Ru Cup 2018 Round 2 B】 Alice and Hairdresser

    [链接] 我是链接,点我呀:) [题意] [题解] 因为只会增加. 所以. 一开始暴力算出来初始答案 每次改变一个点的话. 就只需要看看和他相邻的数字的值就好. 看看他们是不是大于l 分情况增加.减少 ...

  7. Linux学习总结(3)——Linux实用工具

    1. Windows下同步Linux文件(Linux安装Samba和配置) 场景需求: 安装了Ubuntu在虚拟机上,但是代码编辑或者其它更多的操作的时候,还是习惯在windows下进行.如果wind ...

  8. nyoj_71_独木舟上的旅行_201312122051

    独木舟上的旅行 时间限制:3000 ms  |           内存限制:65535 KB 难度:2   描述 进行一次独木舟的旅行活动,独木舟可以在港口租到,并且之间没有区别.一条独木舟最多只能 ...

  9. nyoj_33_蛇形填数_201308221636

    蛇形填数时间限制:3000 ms  |  内存限制:65535 KB 难度:3描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为:10 11 12 19 16 13 28 ...

  10. 洛谷 P1479 宿舍里的故事之五子棋

    P1479 宿舍里的故事之五子棋 题目描述 宿舍里好多好多有趣的事! 7890653今天看到不知何时流行的五子棋,在宿舍里拿个本子,画一些格子,一个棋盘就做好了! 当7890653把目光放到棋上,突发 ...