poj 1286&&poj2409 Polya计数 颜色匹配
#include <iostream>
#include <math.h> using namespace std; #define LL long long
LL gcd(LL a, LL b)
{
return b ? gcd(b, a % b) : a;
} LL polya(LL n)
{
LL ret = ;
for(LL i = ; i < n; i++)
ret += pow(, gcd(i, n));
//flip them...
if( n & )//odd
ret += n * pow(, n / + );//symmetric axis's num is n, and a cycle of (n + 1) / 2, with the length of 2, and 2 cycles with length of 1... else//even ret += n / 2 * pow(3, n / 2) + (n / 2) * pow(3, n / 2 + 1);//symmetric axis's num is n, categoried by the beeds, for n/2 axis which through the beed, they formed (n/2-1) cycles with the length of 2, and 2 cycles with the length of 1; for the n/2 axis which not through the beed, they formed (n/2) cycles with the length of 2.
else//even
ret += n / * pow(, n / ) + (n / ) * pow(, n / + );// return ret / n / ;//the average of them(according to Polya Theorem.)
} int main()
{
LL n;
while(cin>> n && n != -)
{
if (n <= ) cout << << endl;
else cout << polya(n) << endl;
}
return ;
}
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath> using namespace std;
#define n 3 __int64 m; int gcd(int a, int b)
{
b = b % a;
while (b)
{
a = a % b;
swap(a, b);
}
return a;
} int main()
{
while (scanf("%lld", &m)!=EOF)
{
if(m==-)
break;
__int64 ans = ;
for (int i = ; i <= m; i++)
ans += pow(n*1.0, gcd(i, m)*1.0);
if (m & )
ans += m * pow(n*1.0, (m / + )*1.0);
else
ans += m / * pow(n*1.0, (m / )*1.0) + m / * pow(n*1.0, (m / + )*1.0);
ans /= m * ;
printf("%I64d\n", ans);
}
return ;
}
poj 1286&&poj2409 Polya计数 颜色匹配的更多相关文章
- POJ 1286 【POLYA】
题意: 给你三种颜色的珠子,每次给你N,问在旋转,翻转之后视作相同的情况下,能组成多少种不同的项链. 思路: 让我们借这道题拯救一下我对POLYA定理的理解... sigma(m^(gcd(i,n)) ...
- [ACM] POJ 2154 Color (Polya计数优化,欧拉函数)
Color Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7630 Accepted: 2507 Description ...
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- Polya计数
Let it Bead Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5365 Accepted: 3585 Descr ...
- 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 ...
- 《程序设计中的组合数学》——polya计数
我们在高中的组合数学中常常会碰到有关涂色的问题,例如:用红蓝两种颜色给正方形的四个顶点涂色,会有几种不同的方案.在当时,我们下意识的认为,正方形的四个顶点是各不相同的,即正方形是固定的.而实际上我们知 ...
- hdu 5868 Polya计数
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
- hdu 2865 Polya计数+(矩阵 or 找规律 求C)
Birthday Toy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 组合数学及其应用——polya计数
在处理类似下面的问题中,一般的计数方法会出现问题:假如你要用红.蓝两种颜色给一个正四面体的四个顶点着色,试问存在多少种不同的着色方案? 在高中我们常用的方法是模拟涂色过程,分情况讨论,然后基于分步乘法 ...
随机推荐
- Kinect2在线重建(Tracking and Mapping)
前言 个人理解错误的地方还请不吝赐教,转载请标明出处,内容如有改动更新,请看原博:http://www.cnblogs.com/hitcm/ 如有任何问题,feel free to ...
- iOS设置导航栏标题
方法一:在UIViewController中设置self.title. 方法二:设置self.navigationItem.titleView.
- git 查看远程分支、本地分支、创建分支、把分支推到远程repository、删除本地分支
1 查看远程分支 $ git branch -a * br-2.1.2.2 master remotes/origin/HEAD -> origin/master remotes/origin/ ...
- #include <cstdio>
#include <cstdio> using namespace std; int main() { int gx; gx=6; printf("%d\n",gx); ...
- 设计模式:Context模式
作者:吴香伟 发表于 2014/09/12 版权声明:可以任意转载,转载时务必以超链接形式标明文章原始出处和作者信息以及版权声明 Ceph实现中使用了大量派生于Context抽象类的子类,用法简单却很 ...
- svn安装与其服务器搭建
1.概述:SVN为程序开发团队常用的代码管理,版本控制软件. 2.工具: 1) TortoiseSVN-1.8.4.24972-win32-svn-1.8.5.msi SVN安装包. 2)setup ...
- android sdk镜像站点
http://android-mirror.bugly.qq.com:8080/include/usage.html Windows A. 打开Android SDK Manager B. 设置代理 ...
- 结构化查询语言(SQL)数据类型
简要描述一下结构化查询语言中的五种数据类型:字符型,文本型,数值型,逻辑型和日期型. 字符型 VARCHARVS CHAR VARCHAR型和CHAR型数据的这个差别是细微的,但是非常重要.他们都是用 ...
- Http请求中Content-Type讲解以及在Spring MVC中的应用
引言: 在Http请求中,我们每天都在使用Content-type来指定不同格式的请求信息,但是却很少有人去全面了解content-type中允许的值有多少,这里将讲解Content-Type的可用值 ...
- linux系统编程之错误处理机制
在讲解liunx错误处理机制之前我们先来看一段代码: #include<sys/types.h> #include<sys/stat.h> #include<fcntl. ...