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定理求解,对于排成一排的带编号的小球,按照某一种方案改 ...
随机推荐
- Unity学习笔记(3):获取对象
在上一篇文章中(Unity映射注册)中概要介绍了Unity中的映射机制,本节主要介绍对象获取,包括默认获取,通过名称获取,获取全部对象,同时通过加载配置文件,然后再获取对象. 通过代码获取对象 方式1 ...
- [python] 字符串引用
%s str %d 整数 %f 浮点数 print('$%.03f' % 30.1777) >>>$30.178 #四舍五入 print( '%-5s %s %10s' % ('J ...
- MySQL创建数据库[保存mojo格式的数据库]已经常用的utf8格式数据库
一.创建最新编码utf8mb4格式的库: CREATE DATABASE IF NOT EXISTS yourdbname CHARACTER SET utf8mb4 COLLATE utf8mb4_ ...
- Oracle中的USEREVN()
Oracle中的USEREVN() 1.USEREVN() 返回当前用户环境的信息,opt可以是: ENTRYID,SESSIONID,TERMINAL,ISDBA,LABLE,LANGUAGE,CL ...
- ARC工程中添加非ARC文件
转载自:http://blog.csdn.net/zhenweicao/article/details/16988543 分类: IOS2013-11-27 17:02 626人阅读 评论(0) 收藏 ...
- 正则表达式通过Unicode属性匹配
原文链接:http://zochen.iteye.com/blog/690716 Unicode 编码并不只是为某个字符简单定义了一个编码,而且还将其进行了归类. \pP 其中的小写 p 是 prop ...
- 深层解析:构建facebook应用商店推荐引擎
Under the Hood: Building the App Center recommendation engine As more apps on Facebook Platform ha ...
- nginx流量带宽等请求状态统计( ngx_req_status)
介绍 ngx_req_status用来展示nginx请求状态信息,类似于apache的status,nginx自带的模块只能显示连接数等等信息,我们并不能知道到底有哪些请求.以及各url域名所消耗的带 ...
- C# 5.0 TAP 模式下的HTTP Get和Post
标题有点瘆人,换了工作之后很少写代码了,之前由于签了保密协议,不敢把代码拿出来分享给大家,只能摘抄网上的, 今斗胆拿出来晒晒,跪求指点,直接上代码吧 public class HTTPHelper : ...
- [转载]Unity3D的断点调试功能
断点调试功能可谓是程序员必备的功能了.Unity3D支持编写js和c#脚本,但很多人可能不知道,其实Unity3D也能对程序进行断点调试的.不过这个断点调试功能只限于使用Unity3D自带的MonoD ...