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. js 判断 微信浏览器

    <script type="text/javascript"> window.onload = function() { isWeixinBrowser(); } // ...

  2. JS数组reduce()方法

    1.语法 arr.reduce(callback,[initialValue]) reduce 为数组中的每一个元素依次执行回调函数,不包括数组中被删除或从未被赋值的元素,接受四个参数:初始值(或者上 ...

  3. 【原创】使用HTML5+canvas+JavaScript开发的原生中国象棋游戏及源码分享

    目前已经实现的功能: V1.0 : 实现棋子的布局,画布及游戏场景的初始化V2.0 : 实现棋子的颜色改变V3.0 :实现所有象棋的走棋规则V4.0 : 实现所有棋子的吃子功能 GItHub源码下载地 ...

  4. 基于vue的nuxt框架cnode社区服务端渲染

    nuxt-cnode 基于vue的nuxt框架仿的cnode社区服务端渲染,主要是为了seo优化以及首屏加载速度 线上地址 http://nuxt-cnode.foreversnsd.cngithub ...

  5. 弹层蒙版(mask),ios滚动穿透,我们项目的解决方案

    问题描述 项目开发遇到一个ios独有的问题,在wkwebview中稳定复现 问题: 弹出一个蒙版,当在蒙版上面滑动的时候蒙版后面的内容滚动了 这当然是ios的bug,但是经过我们测试iphone7也会 ...

  6. proxy 跨域配置, 针对有axios的baseURL

    1.首先主要的config文件下的index.js中的proxytable配置 proxyTable:{ '/proxy': { target:'http://192.168.2.141:8080', ...

  7. linux - redis基础

    目录 linux - redis基础 redis 源码编译安装 redis 数据结构 1. strings类型 2. list 类型 3. sets集合类型 有序集合 5. 哈希数据结构 centos ...

  8. 【Codeforces 27A】Next Test

    [链接] 我是链接,点我呀:) [题意] 让你求没出现过的最小值 [题解] 模拟..for一下就好 [代码] import java.io.*; import java.util.*; public ...

  9. Codeforces Problem 778B Bitwise Formula

    题目链接:http://codeforces.com/contest/779/problem/E 题意:有n个变量都可以用m位二进制数表示,这n个数的value将以两种格式中的一种给出 1.变量名, ...

  10. ReatEasy+用户指南----第9章@MatrixParam

    转载说明出处:http://blog.csdn.net/nndtdx/article/details/6870391 原文地址 http://docs.jboss.org/resteasy/docs/ ...