poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)
题目: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定理)的更多相关文章
- 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定理)
http://poj.org/problem?id=1286 题意:求用3种颜色给n个珠子涂色的方案数.polya定理模板题. #include <stdio.h> #include &l ...
- 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 & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- 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 ...
- POJ 2409 Let it Bead(polya裸题)
题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...
- POJ 2409 Let it Bead(Polya定理)
点我看题目 题意 :给你c种颜色的n个珠子,问你可以组成多少种形式. 思路 :polya定理的应用,与1286差不多一样,代码一改就可以交....POJ 1286题解 #include <std ...
- POJ 2409 Let it Bead 组合数学
题目地址: http://poj.org/problem?id=2409 给你一串珠子有m个,用n种不同的颜色涂色,问有多少种分法. 用polay定理求解,对于排成一排的带编号的小球,按照某一种方案改 ...
随机推荐
- Java Thread and runnable
java中可有两种方式实现多线程, 一种是继承Thread类,(Thread本身实现了Runnable接口,就是说需要写void run 方法,来执行相关操作) 一种是实现Runnable接口 sta ...
- [Linux]学习笔记(2)
本节主要学习: whoami who am i who w users tty 6个命令的用法. (1)whoami whoami用于查询当前是以哪个用户登录Linux系统: [root@linuxf ...
- LM算法
最小二乘法的概念 最小二乘法的目标:求误差的最小平方和,对应有两种:线性和非线性. 线性最小二乘的解是closed-form即x=(A^T A)^{-1}A^Tb, 而非线性最小二乘没有closed- ...
- 《WPF程序设计指南》读书笔记——第6章 Dock与Grid
1.DockPanel面板 using System; using System.Windows; using System.Windows.Controls; using System.Window ...
- closest()一个在评论里很有用的函数
实例 本例演示如何通过 closest() 完成事件委托.当被最接近的列表元素或其子后代元素被点击时,会切换黄色背景: $( document ).bind("click", fu ...
- php5函数库
* APC缓存 apc_add — 缓存一个变量到数据存储 * DateTime DateTime::addDateTime::diffDateTime::formatDateTime::modify ...
- 创建dblink 同义词
database link dblink的主要作用是两个数据库间的数据访问 create database link my_test connect to testdbname identified ...
- Entity Framework 安装出现问题
Entity Framework 详情请看: http://ulfqbpl.blog.163.com/blog/static/8778355220126272473276/
- hibernate映射文件基础
一.利用hibernate的eclipse插件快速生成实体类与配置文件的方法 1.首先下载安装和自己的eclipse版本配套的hibernate tools,如果是Myeclipse,在/readme ...
- SSH开发框架搭建参考
一, 参考文章: 1, http://blog.csdn.net/communicate_/article/details/8644040 这篇文章讲的还算详尽,但是貌似有一些多余的代码: 2,