题目: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. A version is required for an API group definition.

    A version is required for an API group definition.

  2. Div 内部所有元素 全部垂直对齐

    http://stackoverflow.com/questions/7273338/how-to-vertically-align-an-image-inside-div How it works: ...

  3. [译]Java Thread join示例与详解

    Java Thread join示例与详解 Java Thread join方法用来暂停当前线程直到join操作上的线程结束.java中有三个重载的join方法: public final void ...

  4. TDBAdvGrid 只读状态下复制功能

    DataSource1.AutoEdit := false;

  5. scala知识点(一)

    1.drop,dropRight,dropWhile drop: drop(n: Int): List[A] 丢弃前n个元素,返回剩下的元素 dropRight: dropRight(n: Int): ...

  6. 找不到 com.google.zxing.ResultMetadataType 异常解决

    在 https://github.com/zxing/zxing 下载二维码扫描 将 android 导入,code打成jar包运行时 报 06-14 23:43:08.690: E/AndroidR ...

  7. psutil--跨平台的进程管理

    原文地址:http://www.jianshu.com/p/64e265f663f6 Python处理Windows进程 psutil(Python system and process utilit ...

  8. 【发问】代表ODBC、Ibatis 发问 Hibernate、Linq、Entity、JPA

    分页: 多表关联查询: 多表操作 临时表: 存储过程式长语句 : Hibernate与iBATIS的比较 博客分类: db iBATISHibernateSQL数据结构ORM  1.出身 hibern ...

  9. [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)(转)

    转载自:http://blog.csdn.net/onlyou930/article/details/9299169 分类: Objective-C2013-07-11 11:54 3420人阅读 评 ...

  10. ExtJs gridPanel Column 时间格式化

    var panel = new Ext.container.Viewport({ items: { xtype: 'gridpanel', id: 'gridPanel', store: store, ...