Necklace of Beads(polya定理)
http://poj.org/problem?id=1286
题意:求用3种颜色给n个珠子涂色的方案数。polya定理模板题。
#include <stdio.h>
#include <math.h> long long gcd(long long a,long long b)
{
return b?gcd(b,a%b):a;
}
int main()
{
long long n;
while(~scanf("%lld",&n))
{
if (n==-)
break;
if (n <= )
{
printf("0\n");
continue;
}
long long ans = ;
for (int i = ; i < n; i++)
{
ans+=pow(,gcd(i,n));
}
if (n&)
ans+=n*pow(,n/+);
else
{
ans+=n/*pow(,n/)+n/*pow(,n/+);
}
printf("%lld\n",ans/n/);
}
return ;
}
同类型的题:
http://poj.org/problem?id=2409
#include <stdio.h>
#include <math.h>
long long gcd(long long a,long long b)
{
return b?gcd(b,a%b):a;
}
/*long long pow(long long a,long long b)
{
long long res = 1;
while(b)
{
if (b&1)
res*=a;
a*=a;
b>>=1;
}
return res;
}*/
int main()
{
int n,k;
while(~scanf("%d%d",&k,&n))
{
if (k==&&n==)
break;
long long ans = ;
for (int i = ; i < n; i++)
{
ans+=pow(k,gcd(i,n));
}
if (n&)
ans+=n*pow(k,n/+);
else
{
ans+=n/*pow(k,n/)+n/*pow(k,n/+);
}
printf("%lld\n",ans/n/);
}
return ;
}
Necklace of Beads(polya定理)的更多相关文章
- 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 (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- Necklace of Beads(polya计数)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7451 Accepted: 3102 ...
- hdu 1817 Necklace of Beads (polya)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Necklace of Beads (polya定理的引用)
Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n &l ...
- hdu 1817 Necklace of Beads(Polya定理)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- POJ 1286 Necklace of Beads(Polya定理)
点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
随机推荐
- What is gradle sync in Android Studio?
What is it? And what does it do? Gradle sync is a gradle task that looks through all of your depende ...
- 【数据结构】C语言栈的基本操作
#include<stdio.h> #include<stdlib.h> #include<malloc.h> //定义节点 struct Node { int d ...
- soui edit passwrod模式下禁用输入法
一直在用soui做客户端界面,今天发现密码edit在中文输入法下不能输入密码.我在想难道不是这样吗,密码就该用英文输入法啊. 然后我就用mfc的做了个demo,发现mfc的edit在密码模式下是可以用 ...
- [luogu2591 ZJOI2009] 函数
传送门 Solution 画图找规律.. Code //By Menteur_Hxy #include <cstdio> #define min(a,b) ((a)>(b)?(b): ...
- JS练习:商品的左右选择
代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...
- 网络编程:tcp、udp、socket、struct、socketserver
一.TCP.UDP 一.ARP(Address Resolution Protocol)即地址解析协议,用于实现从 IP 地址到 MAC 地址的映射,即询问目标IP对应的MAC地址. 二.在网络通信中 ...
- 25.TF&IDF算法以及向量空间模型算法
主要知识点: boolean model IF/IDF vector space model 一.boolean model 在es做各种搜索进行打分排序时,会先用boolean mo ...
- 我理解的数据结构(一)—— 数组(Array)
我理解的数据结构(一)-- 数组(Array) 首先,我是一个phper,但是毕竟php是一个脚本语言,如果使用脚本语言去理解数据结构具有一定的局限性.因为脚本语言是不需要编译的,如果你的语法写的不错 ...
- vue项目中的常见问题(vue-cli版本3.0.0)
一.样式问题 1.vue中使用less 安装less依赖 npm install less less-loader --save-dev 在使用时 在style标签中加入 lang="les ...
- 洛谷P3375【模板】KMP字符串匹配
题目描述 如题,给出两个字符串s1和s2,其中s2为s1的子串,求出s2在s1中所有出现的位置. 为了减少骗分的情况,接下来还要输出子串的前缀数组next. (如果你不知道这是什么意思也不要问,去百度 ...