zoukankan      html  css  js  c++  java
  • poj 1286 polya定理

    Necklace of Beads

    Description

    Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are produced by rotation around the center of the circular necklace or reflection to the axis of symmetry are all neglected, how many different forms of the necklace are there?

    Input

    The input has several lines, and each line contains the input data n.
    -1 denotes the end of the input file.

    Output

    The output should contain the output data: Number of different forms, in each line correspondent to the input data.

    Sample Input

    4
    5
    -1

    Sample Output

    21
    39

    Solution

    polya定理模板题

    (overline{G})是n个对象的一个置换群, 用m种颜色染图这n个对象,则不同的染色方案数为:

    [L=frac{1}{|overline{G}|}[m^{c(overline{p_1)}}+m^{c(overline{p_2)}}+...+m^{c(overline{p_g)}}] ]

    其中 (overline{G}={overline{p_1},overline{p_2},...,overline{p_g}})(c(overline{p_k}))(overline{p_k}) 的循环节数(阶)

    如对于n=4:
    单位元:仅有(1)(2)(3)(4)一种情况,((1)^4*1)
    考虑旋转(pm90^circ),有((1234)^1),((1432)^1)两种情况,((4)^1*2)
    考虑旋转(180^circ),有(13)(24)一种情况,((2)^2*1)
    考虑以两个对立顶点为轴翻转,有(1)(3)(24),(2)(4)(13)两种情况,((1)^2(2)^1*2)
    考虑以一不经过任一顶点但平分多边形的直径翻转,有(12)(34),(13)(24)两种情况,((2)^2*2)
    所以答案为$$frac{34+312+32+332+3^2*2}{1+2+1+2+2}=21$$


    • 考虑旋转,对于(n)个球的环旋转(i)个球的循环节的个数为(gcd(n,i)),这一部分快速幂求和

    • 考虑奇数的翻转,每次选择一个顶点作对称轴翻转,循环节数为(frac{n+1}{2})(自身不动,剩余两两交换),一共n种选择

    • 考虑偶数的翻转,可选对顶的两顶点作为对称轴旋转,循环节数为(frac{n+2}{2}),(两顶点不动,剩余两两交换),(frac{n}{2}种选择),选择无顶点的对称轴翻转,循环节数为(frac{n}{2})(全部两两交换),(frac{n}{2})种选择

    #include <algorithm>
    #include <cctype>
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #if __cplusplus >= 201103L
    #include <unordered_map>
    #include <unordered_set>
    #endif
    #include <vector>
    #define lson rt << 1, l, mid
    #define rson rt << 1 | 1, mid + 1, r
    #define LONG_LONG_MAX 9223372036854775807LL
    #define ll LL
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef pair<int, int> P;
    int n, m, k;
    const int maxn = 1e5 + 10;
    ll qpow(ll a, ll n)
    {
        ll res = 1;
        while (n)
        {
            if (n & 1)
                res *= a;
            a *= a;
            n >>= 1;
        }
        return res;
    }
    ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
    ll solve()
    {
        ll res = 0;
        if (!n)
            return res;
        for (int i = 1; i <= n; i++)
        {
            res += qpow(3, gcd(n, i));
        }
        if (n & 1)
        {
            res += (ll)n * qpow(3, (n + 1) / 2);
        }
        else
        {
            res += (ll)(n / 2) * qpow(3, (n + 2) / 2);
            res += (ll)(n / 2) * qpow(3, n / 2);
        }
        return res / (2 * n);
    }
    int main(int argc, char const *argv[])
    {
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        while (cin >> n && n != -1)
        {
            cout << solve() << '
    ';
        }
        return 0;
    }
    
    
  • 相关阅读:
    使用metasploit进行栈溢出攻击-2
    使用metasploit进行栈溢出攻击-1
    如何利用 Visual Studio 自带工具提高开发效率
    Visaul Studio 常用快捷键动画演示
    WinForm AutoComplete 输入提示、自动补全
    RTL2832U+R820T电视棒windows下安装sdr# 以及搭建ADS-B使用VirtualRadar看飞机的教程
    传说中的WCF(12):服务器回调有啥用
    传说中的WCF(11):会话(Session)
    传说中的WCF(10):消息拦截与篡改
    传说中的WCF(9):流与文件传输
  • 原文地址:https://www.cnblogs.com/mooleetzi/p/11355215.html
Copyright © 2011-2022 走看看