• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
UVa 10294 Arif in Dhaka (First Love Part 2) (Polya定理)

题意:给定 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;
}

  

posted on 2018-03-06 22:27  dwtfukgv  阅读(126)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3