Necklace of Beads
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7451   Accepted: 3102

Description

Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are produced by rotation around the center of the circular necklace or reflection to the axis of symmetry are all neglected, how many different forms of the necklace are there? 

Input

The input has several lines, and each line contains the input data n.  -1 denotes the end of the input file. 

Output

The output should contain the output data: Number of different forms, in each line correspondent to the input data.

Sample Input

4
5
-1

Sample Output

21
39
题解:给出红,绿,蓝3种颜色 的n个珠子,求能够组成多少个不同的项链。 (旋转 和 翻转后 相同的属于同一个项链)
看了好久大神的代码还是不太理解;暂时的理解是,对于每个循环节里的元素都有k中染色方案,所以是k^c(f);
现在只需要找出所有循环节的种数就好了;当然翻转和旋转循环节是不同的,翻转和旋转均有n种;所有种数加完要除以2n

Polya定理:

(1)设G是p个对象的一个置换群,用k种颜色给这p个对象,若一种染色方案在群G的作用下变为另一种方案,则这两个方案当作是同一种方案,这样的不同染色方案数为

(2)对于N个珠子的项链,共有n种旋转置换和n种翻转置换。

对于旋转置换:每种置换的循环节数c(fi) = gcd(n,i),(i为一次转过多少个珠子)

对于翻转置换:如果n为奇数,共有n种翻转置换,每种置换的循环节数均为c(f) = n/2 + 1;              如果n为偶数,分两种情况 <1> 从空白处穿对称轴,则轴两边各有n/2个对象,得到c(f) = n/2;

<2> 从两个对象上穿对称轴,则轴两边各有n/2-2个对象,得到c(f) = n/2 + 1。

代码:

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
typedef long long LL;
int gcd(int a,int b){return b==?a:gcd(b,a%b);}
int main(){
int n;
while(~SI(n),n!=-){
LL ans=;
if(!n){
puts("");continue;
}
for(int i=;i<=n;i++)
ans+=pow(,gcd(i,n));
ans+=n*(n&?pow(,n/+):(pow(,n/)/+pow(,n/+)/));
printf("%lld\n",ans/(*n));
}
return ;
}

最新文章

  1. mvc路由,mvc区域
  2. appid 评价
  3. C primer plus 练习题 第五章
  4. DataGridView显示行号的几种方法来自http://www.soaspx.com/dotnet/csharp/csharp_20100204_2740.html
  5. freeCodeCamp:Convert HTML Entities
  6. HDU 5680 zxa and set (数学 推导结论)
  7. 单/多行文本添加省略号 (o゚ω゚o)
  8. IE attachEvent事件处理程序(事件绑定的函数)的this指向的是window不是执行当前事件的dom元素
  9. 基于Java图片数据库Neo4j 3.0.0发布 全新的内部架构
  10. js中访问对象的方法
  11. Git工作流:中心工作流(翻译)
  12. Java: How to resolve Access Restriction error
  13. c#封装DBHelper类
  14. python读取文件内的IP信息 练习
  15. Noi.ac #309. Mas的童年(贪心)
  16. vue打包后,接口请求404的完美解决方案
  17. Cannot create a new pixel buffer adaptor with an asset writer input that has already started writing&#39;
  18. Python 文件内容读取
  19. 决策树与树集成模型(bootstrap, 决策树(信息熵,信息增益, 信息增益率, 基尼系数),回归树, Bagging, 随机森林, Boosting, Adaboost, GBDT, XGboost)
  20. CRF原理解读

热门文章

  1. 深入研究 Win32 结构化异常处理(作者博客有许多SEH的研究文章)
  2. gcc选项-g与-rdynamic的异同
  3. magento产品导入时需要注意的事项
  4. python Debug 单步调试
  5. Windowsclient开发简单介绍(四)
  6. CSDN博文大赛火爆开启
  7. 调用Response.Redirect 捕获异常 解决办法(摘抄)
  8. php get_magic_quotes_gpc() addslashes()
  9. Linux学习4——Vim和Bash
  10. android开发SD卡工具类(一)