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计数
在处理类似下面的问题中,一般的计数方法会出现问题:假如你要用红.蓝两种颜色给一个正四面体的四个顶点着色,试问存在多少种不同的着色方案? 在高中我们常用的方法是模拟涂色过程,分情况讨论,然后基于分步乘法 ...
随机推荐
- Noip2016提高组 组合数问题problem
Day2 T1 题目大意 告诉你组合数公式,其中n!=1*2*3*4*5*...*n:意思是从n个物体取出m个物体的方案数 现给定n.m.k,问在所有i(1<=i<=n),所有j(1< ...
- python 自动发邮件 Errno61 Connection refused
此问题是在mac机器上遇到 之前在windows平台运行ok的脚本在mac上报错 后来查了半天 发现是网络接入不对 切换下网络后问题就解决了
- 动态生成DropDownList 并取值
Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Def ...
- java 删除所有HTML工具类
import java.util.regex.Matcher;import java.util.regex.Pattern; public class HtmlUtil { private stati ...
- Office组件之Spire.XLS的DotNet操作
Overview 在项目中,我们经常需要将程序中获得的大量数据导出到Excel表格中,打印报表:进一步,还可能生成其折线图,对数据的变化趋势进行分析,从而更好地开展项目工作. 最近,我发现了一个对于D ...
- android webview开发问题及优化汇总
我们在native与网页相结合开发的过程中,难免会遇到关于WebView一些共通的问题.就我目前开发过程中遇到的问题以及最后得到的优化方案都将在这里列举出来.有些是老生常谈,有些则是个人摸索得出解决方 ...
- hbuilder中如何使用egit上传项目
刚开始使用时,我也是遵照网上的教程来的,其实就那一篇教程,到处被转载,怎么搜都是那一个,实际操作发现有点小不同,所以实际截图给大家一个参考. 1.首先肯定是进入hbuilder下载egit插件啦.(工 ...
- 编辑器sublime text3和插件package control、Sidebar Enhancements插件安装
(1)编辑器sublime text3的安装:选择自己需要的版本下载安装:http://www.sublimetext.com/3 (2)package control插件安装:https://pac ...
- struts2的文件上传
在做B/S系统时,通常会涉及到上传文件和下载文件,在没接struts2框架之前,我们都是使用apache下面的commons子项目的FileUpload组件来进行文件的上传,但是那样做的话,代码看起来 ...
- HTML5+CSS3学习笔记(二) 页面布局:HTML5新元素及其特性
HTML5的语义化标签以及属性,可以让开发者非常方便地实现清晰的web页面布局,加上CSS3的效果渲染,快速建立丰富灵活的web页面显得非常简单. 本次学习HTML5的新标签元素有: <head ...