题目: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. DISCUZ! X2.5设置仅允许QQ登录注册论坛 加固会员注册机制

    论坛稍微有点起色之后,很多站长就会担心论坛经常被人恶意灌水.注册机.顶贴机等等一些列非法的手段.通常站长都会通过一些后台的设置和插件等等一 切有效的方法预防,但更多的站长会通过限制用户注册会员,需注册 ...

  2. linux crontab 命令

    Linux 系统提供了使用者控制计划任务的命令 :crontab 命令. 一.crond简介 crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划 ...

  3. 【linQ】DataContext 入门 , 和 hql , jpql 一样好用

    DataContext 和 LINQ结合后会有巨大的能量 public class UserDataContext : DataContext { public Table<User> U ...

  4. iOS 开发一年总结

    收获很多 1. 一个人包办从构思, 设计, 实现, 推广的全过程, 对自己的能力, 特别是能力范围有很大的提升. 以前在公司上班仅仅局限在实现的局域内, 现在在做自己的产品时, 在设计时的取舍, 对工 ...

  5. 关于MySQL Connector/C++那点事儿

    如果从官方直接下载的库使用时遇到类似如下的问题: 原因是官方提供的库文件版本与需要的库版本不匹配,提供的debug版本使用的是MT版本,在debug模式下会出现内存错误,导致crash. TestC. ...

  6. C# 将datatable 转换json

    public static string DataTableToJson(DataTable dt) { StringBuilder jsonBuilder = new StringBuilder() ...

  7. EXTJS 3.0 资料 控件之 GridPanel属性与方法大全

    1.Ext.grid.GridPanel 主要配置项: store:表格的数据集 columns:表格列模式的配置数组,可自动创建ColumnModel列模式 autoExpandColumn:自动充 ...

  8. Sambar,实现Linux和Windows共享

    我下载的是tar的jar包,不是rpm,rpm就不多说了.目的是让Windows能够共享Linux系统的文件夹 1.进入到source文件夹: 2../configure->make->m ...

  9. maven3.1.1适合搭配的jdk版本

    maven 可以帮助我们管理项目的jar 不同的版本对jdk的要求也不相同, 比如3.1.1就要搭配1.6或以上的jre但是1.7有的版本还是会有点问题 当maven所需的jre版本不对应时项目会报错 ...

  10. drag drop小游戏

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...