Necklace of Beads(polya定理)
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 ;
}
同类型的题:
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定理)的更多相关文章
- poj1286 Necklace of Beads—— Polya定理
题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...
- POJ1286 Necklace of Beads(Polya定理)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9359 Accepted: 3862 Description Beads ...
- poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- Necklace of Beads(polya计数)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7451 Accepted: 3102 ...
- hdu 1817 Necklace of Beads (polya)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Necklace of Beads (polya定理的引用)
Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n &l ...
- hdu 1817 Necklace of Beads(Polya定理)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- POJ 1286 Necklace of Beads(Polya定理)
点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
随机推荐
- mysql幻读
开启a,b两个数据库连接,a.b都开启事务后,b插入了一条数据R并提交,验证对a的操作造成的影响 select select for update update R update R 后 select ...
- css的基本单词
<border>边框 border边框 <text>文本 text文本 <indent>缩进 indent缩进 <align>对齐方式 align对齐方 ...
- day07-列表类型/元组类型/字典类型/集合类型内置方法
目录 列表类型内置方法 元组类型内置方法 字典类型内置方法 集合类型内置方法 列表类型内置方法 用来存多个元素,[]内用逗号隔开任意数据类型的元素 1. list()强制类型转换 print(list ...
- 关于JS中的方法是否加括号的问题
js中的方法什么时候加括号什么时候不加括号呢,我们有时候经常就搞不清楚,记住下面这几点就好理解了. 1.函数做参数时都不要加括号. function fun(a){ alert(a); } funct ...
- jq购物车结算功能
css *{font-style: normal} .gw{margin: 8px;} .gw::after{display: block;clear: both;content: '';margin ...
- HDU 1465(错排公式)
不容易系列之一 题意: 一个人要寄n个信封,结果装错了.信纸的编号为1到n,信封的编号为1到n,信纸的编号不能和信封的编号一样,全都不能一样. 思路:错排公式. D(n)表示n件信封装错的所有的情况. ...
- 16.copy_to定制组合field解决cross-fields搜索弊端
主要知识点: 在index的mapping中加copy_to字段的方法 copy_to搜索方法 用most_fields策略,去实现cross-fields搜索,有3大弊端,为了解决这三个弊端 ...
- ASP.NET误人子弟教程:在MVC下如何返回图片
这几天忙着一些小事,也没有写什么了,今天,我们来玩一个比较简单的东东.就是在MVC下如何返回图片,相信,在传统WebForm下,大家都晓得怎么弄,方也不限于一种,但是,在架构较为严格的MVC里面,刚开 ...
- Django基础配置
安装djangopip install Django==1.11.4进入pythonimport django查看版本号django.get_version()创建项目,在合适位置创建一个目录进入你要 ...
- C# 派生类的XmlSerializer序列化XML
近段对XML 序列化进行处理,用XmlSerializer这个挺好用的. 但是对于派生类对象的XML的生成总会报错.因为同一个节点名称,不能反射为不同的对象.这个在网上找了好久,都说要利用反射来处理. ...