poj1286 Necklace of Beads【裸polya】
非常裸的polya,只是我看polya看了非常久
吉大ACM模板里面也有
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
long long gcd(long long a,long long b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("G:/1.txt","r",stdin);
//freopen("G:/2.txt","w",stdout);
#endif
long long p[33];
p[0]=1;
for(long long i=1;i<=24;i++)
{
p[i]=p[i-1]*3;
//cout<<p[i]<<endl;
}
long long res=0;
long long s;
while(cin>>s)
{
if(s==-1)
break;
if(s==0)
{
cout<<"0\n";
continue;
}
long long res=s&1?s*p[s/2+1]:(s/2)*(p[s/2]+p[s/2+1]);
for(long long k=1;k<=s;k++)
{
res+=p[gcd(k,s)];
}
res/=2*s;
cout<<res<<'\n';
}
return 0;
}
poj1286 Necklace of Beads【裸polya】的更多相关文章
- POJ 1286 Necklace of Beads(Polya简单应用)
Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...
- hdu 1817 Necklace of Beads(Polya定理)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- POJ1286 Necklace of Beads(Polya定理)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9359 Accepted: 3862 Description Beads ...
- 【数论】【Polya定理】poj1286 Necklace of Beads
Polya定理:设G={π1,π2,π3........πn}是X={a1,a2,a3.......an}上一个置换群,用m中颜色对X中的元素进行涂色,那么不同的涂色方案数为:1/|G|*(mC(π1 ...
- poj1286 Necklace of Beads—— Polya定理
题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...
- POJ 1286 Necklace of Beads(Polya原理)
Description Beads of red, blue or green colors are connected together into a circular necklace of n ...
- Necklace of Beads (polya定理的引用)
Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n &l ...
- POJ1286 Necklace of Beads
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8263 Accepted: 3452 Description Beads ...
- 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. ...
随机推荐
- c语言system()介绍
2013-09-0916:06:02 1. 头文件: #include <stdlib.h> 2. 定义函数: int system(const char * string); 3. 函数 ...
- jquery.reveal弹出框
一款js弹出框,嵌入其它页面: 引用: <script src="../../js/jquery.reveal.js" type="text/javascript ...
- vscode中eslint airbnb的简单配置
vscode可以直接在扩展中下载安装eslint,然后,还不能用,需要继续如下步骤: 1.npm install -g eslint 安装完后输入"eslint",有东西出来说明安 ...
- 关于电脑安装新硬盘,出现无法是识别设备,03F0问题解答。
问题说明:在添加新的硬盘,切确定硬盘没有坏的情况下,无法识别出新的硬盘. 解决方案: 1.检查bios系统里的安全模式,是否处于开启中.因为在windows 8.1以上的版本中,不开启的情况下只能读取 ...
- java RPC系列之一 rmi
java RPC系列之一 rmi 一.java RPC简单的汇总 java的RPC得到技术,基本包含以下几个,分别是:RMI(远程方法调用) .Caucho的Hessian 和 Burlap . ...
- Warning:关于_CRT_SECURE_NO_WARNINGS
Warning 1 warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s in ...
- openlayers5学习笔记-map事件(moveend)
//事件:地图移动结束 tmp.map.on('moveend', function (evt) { console.log(evt.frameState.extent); }); evt.frame ...
- Kattis - Game Rank
Game Rank Picture by Gonkasth on DeviantArt, cc by-nd The gaming company Sandstorm is developing an ...
- python tips: is同一性运算符
is用来判断两个对象是不是同一个对象,通过id()函数取对象地址进行判断.python会缓存一些小的整数,以及只包含字母数字以及下划线的字符串.所以在对于这些值的时候,is判断为True. >& ...
- JS 封装一个求圆面积的函数 传值:半径
y(6) var s = ""; function y (r){ s = Math.PI*r*r; alert(s); }