POJ2409 Let it Bead(Polya定理)
2024-09-04 17:39:04
Let it Bead
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6443 | Accepted: 4315 |
Description
"Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets. However, over 90 percent of the target audience insists that the bracelets be unique. (Just imagine what happened if two women showed up at the same party wearing identical bracelets!) It's a good thing that bracelets can have different lengths and need not be made of beads of one color. Help the boss estimating maximum profit by calculating how many different bracelets can be produced.
A bracelet is a ring-like sequence of s beads each of which can have one of c distinct colors. The ring is closed, i.e. has no beginning or end, and has no direction. Assume an unlimited supply of beads of each color. For different values of s and c, calculate the number of different bracelets that can be made.
Input
Every line of the input file defines a test case and contains two integers: the number of available colors c followed by the length of the bracelets s. Input is terminated by c=s=0. Otherwise, both are positive, and, due to technical difficulties in the bracelet-fabrication-machine, cs<=32, i.e. their product does not exceed 32.
Output
For each test case output on a single line the number of unique bracelets. The figure below shows the 8 different bracelets that can be made with 2 colors and 5 beads.
Sample Input
1 1
2 1
2 2
5 1
2 5
2 6
6 2
0 0
Sample Output
1
2
3
5
8
13
21
Source
感觉这玩意儿认真的好神奇啊qwq。
为什么网上都是直接说循环节的大小但是不做说明qwq、、
算了还是背结论吧
若是直接旋转,那么有$n$中置换,第$i$种循环节数为$gcd(n, i)$
如果是对称
对于奇数来说,可以固定一个点,让其他点交换。共有$n$个点,每种循环节为$\frac{n + 1}{2}$
对于偶数来说,有两种对称方式,
一种是以中线为中心,两边对称,共有$N / 2$种方式,每种循环节为$\frac{n + 2}{2}$
另一种是两个点的连线为中心,两边对称,共有$N/ 2$种方式,每种循环节为$\frac{n}{2}$
然后直接上polya定理就行了
POJ的评测机也是没谁了
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#define LL long long
const int MAXN = 1e5 + ;
using namespace std;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int C, N;
int fastpow(int a, int p) {
int base = ;
while(p) {
if(p & ) base = base * a;
a = a * a; p >>= ;
}
return base;
}
main() {
while(scanf("%d %d", &C, &N)) {
if(C == && N == ) break;
int ans = ;
for(int i = ; i <= N; i++) ans += fastpow(C, __gcd(i, N));
if(N & ) ans = ans + N * fastpow(C, (N + ) / );
else ans = ans + N / * (fastpow(C, (N + ) / ) + fastpow(C, N / ));
printf("%d\n", ans / / N);
}
}
最新文章
- [Docker]Docker快速上手学习笔记
- [云上天气预报-有时有闪电]2月3日23:00-4:00阿里云SLB升级期间网络会闪断
- 基于web的IM软件通信原理分析
- BestCoder Round #73
- 微信浏览器里location.reload问题
- 手势识别官方教程(8)拦截触摸事件,得到触摸的属性如速度,距离等,控制view展开
- [转]NHibernate之旅(11):探索多对多关系及其关联查询
- 中秋佳节--理解Enum枚举
- Swing图层的应用——实现tooltip显示
- Microsoft Edge浏览器下载文件乱码修复方法
- React 入门学习笔记整理目录
- Selenium Webdriver 中的 executeScript 使用方法
- EChart.js 笔记一
- log4j.appender.file.DatePattern
- 20145109竺文君、20145106石晟荣 java实验三
- HDU 5150 Sum Sum Sum 素数
- json-lib 之jsonConfig详细使用(转载写的不错)
- ubuntu安装flashplayer插件三步走
- Beautiful Soup的一些中文资料
- react 坑总结