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

题意:用k种不同的颜色给长度为n的项链染色

网上大神的题解:

1.旋转置换:一个有n个旋转置换,依次为旋转0,1,2,```n-1。对每一个旋转置换,它循环分解之后得到的循环因子个数为gcd(n,i).

2.翻转置换:分奇偶讨论。

奇数的时候 翻转轴 = (顶点+对边终点的连线),一共有n个顶点,故有n个置换,且每个置换分解之后的因子个数为n/2+1;

偶数的时候 翻转轴 = (顶点+顶点的连线),一共有n个顶点,故有n/2个置换,且每个置换分解之后的因子个数为n/2+1;

或者 翻转轴 = (边终点+边中点的连线),一共有n个顶点,故有n/2个置换,且每个置换分解之后的因子个数为n/2;

 #include<stdio.h>
#include<math.h> int gcd(int a,int b)
{
if(b)
return gcd(b,a%b);
else
return a;
} double polya(double k,int n)
{
int i; double ans=;
for(i=;i<n;i++)
ans+=pow(k,gcd(n,i));
if(n%)
ans+=n*pow(k,n/+);
else
{
ans+=(n/)*pow(k,n/+);
ans+=(n/)*pow(k,n/);
}
return ans/(*n);
}
int main()
{
int s;
double c;
while(scanf("%lf%d",&c,&s))
{
if(c==||s==)
break;
printf("%.0lf\n",polya(c,s));
}
return ;
}

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

题意:给你n颗珠子,将这n颗珠子围成一个圈形成一串项链,然后对每个珠子涂上红色、蓝色和绿色中的一种。

如果两种涂色方法可以通过旋转项链得到。那么这两种涂色方法视为一种。如果两种涂色方法可以通过一个对

称轴反映得到,那么这两种涂色方法也视为一种。问有多少种不同的涂色方法。

和2409一样的。。

 #include<stdio.h>
#include<math.h> int gcd(int a,int b)
{
if(b)
return gcd(b,a%b);
else
return a;
} int polya(int k,int n)
{
int i; double ans=;
for(i=;i<n;i++)
ans+=pow(k,gcd(n,i));
if(n%)
ans+=n*pow(k,n/+);
else
{
ans+=(n/)*pow(k,n/+);
ans+=(n/)*pow(k,n/);
}
return ans/(*n);
}
int main()
{
int s;
double c;
while(~scanf("%d",&s)&&s!=-)
{
c=;
if(s<=)
printf("0\n");
else
printf("%d\n",polya(c,s));
}
return ;
}

poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)的更多相关文章

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

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

  2. Necklace of Beads(polya定理)

    http://poj.org/problem?id=1286 题意:求用3种颜色给n个珠子涂色的方案数.polya定理模板题. #include <stdio.h> #include &l ...

  3. poj1286 Necklace of Beads—— Polya定理

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

  4. POJ1286 Necklace of Beads(Polya定理)

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

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

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

  6. 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 ...

  7. POJ 2409 Let it Bead(polya裸题)

    题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...

  8. POJ 2409 Let it Bead(Polya定理)

    点我看题目 题意 :给你c种颜色的n个珠子,问你可以组成多少种形式. 思路 :polya定理的应用,与1286差不多一样,代码一改就可以交....POJ 1286题解 #include <std ...

  9. POJ 2409 Let it Bead 组合数学

    题目地址: http://poj.org/problem?id=2409 给你一串珠子有m个,用n种不同的颜色涂色,问有多少种分法. 用polay定理求解,对于排成一排的带编号的小球,按照某一种方案改 ...

随机推荐

  1. 正则应用—queryURLParameter()

    在项目中,我们做详情页的时候,需要获取到用户从哪里来点击进来,获取到用户的点击地址,根据不同的地址传进的参数向服务器获取不同的数据,然后加载不同的详情页面. 大部分企业都采用字符串截取的方式,quer ...

  2. css3选择器一

    在HTML中,通过各种各样的属性可以给元素增加很多附加的信息,了解和掌握css3一些的选择器,是很有必要的. 属性选择器示例: <div><a href="xxx.pdf& ...

  3. C# login with cookie and fiddler2

    http://blog.codeblack.nl/post/HttpWebRequest-HttpWebResponse-and-cookies.aspx CookieContainer cookie ...

  4. [Testing] 測試電子原文書

    測試電子原文書 http://files.cnblogs.com/vincentmylee/SoftwareTesting2ndEdition.7z

  5. C# winfrom中的布局 控件Anchor和Dock的区别

    c#中的布局问题 http://hi.baidu.com/whzpower/item/57e3179cca21e1cab725317a

  6. SQL学习中(一)序列

    序列可以理解数值序列生成器,通俗的说是按照已经设定的规则自动产生数据的方案对象.--SQL SERVER不支持 个人认为序列类似于SQLSERVER中的identity(1,1),可以用于在表中添加数 ...

  7. 【BZOJ2330】 [SCOI2011]糖果

    Description 幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一些要求,比如小明不希望小红分到的糖果比他的 ...

  8. EvnetBus

    领域事件(EvnetBus)   文档目录 本节内容: EventBus 注入 IEventBus 获取默认实例 定义事件 预定义事件 处理完异常 实体修改 触发事件 处理事件 处理基类事件 处理程序 ...

  9. csu 1312 榜单(模拟题)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1312 1312: 榜单 Time Limit: 1 Sec  Memory Limit: 128 ...

  10. linux ubuntu 11.04 samba 服务器设置

    安装 SAMBA 组件 sudo apt-get install samba smbfs smbclient   配置相关参数 sudo gedit /etc/samba/smb.conf 文件中相关 ...