题意:给定 n 和 m 表示要制作一个项链和手镯,项链和手镯的区别就是手镯旋转和翻转都是相同的,而项链旋转都是相同的,而翻转是不同的,问你使用 n 个珠子和 m 种颜色可以制作多少种项链和手镯。

析:一个很明显的 Polya 定理,先考虑旋转,如果逆时针旋转 i 个珠子,那么 0 i 2i 3i ... 是一个循环,这样的话就有 gcd(i, n) 个循环。

对于翻转,要考虑是奇偶,如果是奇数,肯定是要过一个珠子的,所以就一共有 n 个相同的,对于每一个会形成 n/2 个长度为 2 个的循环,和一个长度为 1 的循环(也就是在对称轴上的那个),如果 n 是偶数,那么有两种对称轴一种是过两个珠子,这样的有 n/2 条,形成 n/2-1 个长度为 2 循环,和两个长度为 1 循环(也就是在对称轴上的那两个),再就是不过任何珠子,那么这样的有 n/2 条对称轴,形成 n/2 个的长度为2 的循环。因为题目说了答案不会超过 11 位数字,所以可以用 long long 来解决。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
//#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.in", "r", stdin)
#define freopenw freopen("out.out", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 100 + 10;
const int maxm = 100 + 2;
const LL mod = 100000000;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} LL f[maxn]; int main(){
while(scanf("%d %d", &n, &m) == 2){
f[0] = 1;
for(int i = 1; i <= n; ++i) f[i] = f[i-1] * m;
LL a = 0, b = (n&1) ? n * f[(n+1)/2] : n/2 * (f[n/2+1]+f[n/2]);
for(int i = 0; i < n; ++i) a += f[gcd(i, n)];
printf("%lld %lld\n", a / n, (a+b)/2/n);
}
return 0;
}

  

UVa 10294 Arif in Dhaka (First Love Part 2) (Polya定理)的更多相关文章

  1. Uva 10294 Arif in Dhaka (First Love Part 2)

    Description 现有一颗含\(N\)个珠子的项链,每个珠子有\(t\)种不同的染色.现求在旋转置换下有多少种本质不同的项链,在旋转和翻转置换下有多少种本质不同的项链.\(N < 51,t ...

  2. UVa 10294 Arif in Dhaka (First Love Part 2)(置换)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35397 [思路] Polya定理. 旋转:循环节为gcd(i,n) ...

  3. 【uva 10294】 Arif in Dhaka (First Love Part 2) (置换,burnside引理|polya定理)

    题目来源:UVa 10294 Arif in Dhaka (First Love Part 2) 题意:n颗珠子t种颜色 求有多少种项链和手镯 项链不可以翻转 手镯可以翻转 [分析] 要开始学置换了. ...

  4. [Uva10294]Arif in Dhaka

    [Uva10294]Arif in Dhaka 标签: 置换 Burnside引理 题目链接 题意 有很多个珠子穿成环形首饰,手镯可以翻转和旋转,项链只能旋转.(翻转过的手镯相同,而项链不同) 有n个 ...

  5. UVa 10294(polya 翻转与旋转)

    Arif in Dhaka(First Love Part 2) Input: standard input Output: standard output Time Limit: 2 seconds ...

  6. UVA 10294 项链与手镯 (置换)

    Burnside引理:对于一个置换\(f\), 若一个着色方案\(s\)经过置换后不变,称\(s\)为\(f\)的不动点.将\(f\)的不动点数目记为\(C(f)\), 则可以证明等价类数目为\(C( ...

  7. UVA10294 Arif in Dhaka (群论,Polya定理)

    UVA10294 Arif in Dhaka (群论,Polya定理) 题意 : 给你一个长为\(n\)的项链和手镯,每个珠子有\(m\)种颜色. 两个手镯定义为相同,即它们通过翻转和旋转得到一样的手 ...

  8. UVa 10294 (Pólya计数) Arif in Dhaka (First Love Part 2)

    Burnside定理:若一个着色方案s经过置换f后不变,称s为f的不动点,将置换f的不动点的数目记作C(f).等价类的数目等于所有C(f)的平均值. 一个项链,一个手镯,区别在于一个能翻转一个不能,用 ...

  9. Arif in Dhaka (First Love Part 2) UVA - 10294(Polya定理)

    这题和POJ-1286一样 题意: 给出t种颜色的n颗珠子 (每种颜色的珠子个数无限制,但总数必须是n), 求能制作出项链和手镯的个数 注意手镯可以翻转和旋转  而 项练只能旋转 解析: 注意Poly ...

随机推荐

  1. 安装后没有IP

    修改  /etc/sysconfig/network-scripts/ifcfg-eth0 改为yes

  2. 在BCH硬分叉后防止重放攻击-1

    导致新加密货币的硬分叉为加密交换运营商带来了独特的机遇和挑战.Poloniex在最近的Bitcoin Cash硬叉之后面临的一个挑战是保护我们的客户免受重播攻击.由于SV链后面的开发团队选择在分叉后近 ...

  3. c#异步等待

    1:一直等待 2方法  现实等待 3:方法    带返回值得 begin -endinvoke 4: func 带返回值

  4. ES6解构赋值的应用场景

    一.变量交换 1.ES6的方式 { let a=; let b=; [a,b]=[b,a]; console.log(a,b); } 输出为 2.ES5的方式 采用中间变量的方式进行存储 二.获取函数 ...

  5. APM浅析

    APM(Application Performance Management & Monitoring)一种基于云的性能监控服务(SaaS),以非侵入式监听探针,收集应用关键指标,生成分析报表 ...

  6. 用PS绘制立体字的效果教程

    1. 新建一个透明画布. 2. 利用选区绘制一个圆圈 3. 利用渐变工具绘制渐变 (颜色自拟) 4. 选择混合器画笔工具按住ALT 点击填充颜色的图层 5. 新建画布填充黑色 利用混合画笔进行绘制. ...

  7. url下载文件到本地

    $url = 'http://czd.111.net/extra/car2.jpg'; function download($url, $path = './huahua.jpg') { $ch = ...

  8. Java Swing 中使用 EventQueue

    public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { ...

  9. [Robot Framework] 通过Robot Remote Server调用White Library测试WPF开发的桌面产品

    参考 : https://github.com/jatalahd/WhiteRobotLibrary 通过此源代码编译WhiteRobotLibrary.dll,然后把高亮标记的这5个dll全部拷贝到 ...

  10. Spring ConversionService 类型转换(二) ConversionService

    Spring ConversionService 类型转换(二) ConversionService Spring 系列目录(https://www.cnblogs.com/binarylei/p/1 ...