zoukankan      html  css  js  c++  java
  • Uva 10294 Arif in Dhaka (First Love Part 2)

    Description

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

    Input

    The input file contains several lines of input. Each line contains two positive integers (N (0 < N < 51)) and (t (0 < t < 11)) as described in the problem statement. Also note that within this input range inputs will be such that no final result will exceed 11 digits. Input is terminated by end of file.

    Output

    对于每组数据,输出一行。每行两个数(NN,NB),分别表示在旋转置换,旋转和翻转置换下本质不同的项链数目。

    Sample Input

    5 2
    5 3
    5 4
    5 5

    Sample Output

    8 8
    51 39
    208 136
    629 377

    伯恩赛德引理裸题。考虑每种置换下的不动点数即可。
    旋转:写写应该知道一个轮换内的珠子应该涂相同的颜色,假设旋转(i)位,共有(gcd(i,N))个轮换,所以有(t^{gcd(i,N)})个不动点。
    翻转:假设翻转后再旋转(i)位,画画也能看到轮换个数为(lceil frac{i}{2} ceil + lceil frac{N-i}{2} ceil),所以不动点个数位(t^{lceil frac{i}{2} ceil + lceil frac{N-i}{2} ceil})
    于是就愉快的做完了。

    #include<cstdio>
    #include<cstdlib>
    using namespace std;
    
    typedef long long ll;
    int N,T;ll ans;
    
    inline int gcd(int a,int b) { if (!b) return a; return gcd(b,a%b); }
    inline ll qsm(ll a,int b)
    {
    	ll ret = 1;
    	for (;b;b >>= 1,a = a*a) if (b & 1) ret *= a;
    	return ret;
    }
    
    int main()
    {
    	freopen("10294.in","r",stdin);
    	freopen("10294.out","w",stdout);
    	while (scanf("%d %d",&N,&T) != EOF)
    	{
    		ans = 0;
    		for (int i = 0;i < N;++i) ans += qsm(T,gcd(i,N));
    		printf("%lld ",ans / (ll)N);
    		for (int i = 0;i < N;++i) ans += qsm(T,((i+1)>>1)+((N-i+1)>>1));
    		printf("%lld
    ",ans / (ll)(N<<1));
    	}
    	fclose(stdin); fclose(stdout);
    	return 0;
    }
    
  • 相关阅读:
    JavaScript数组
    JavaScript正则表达式之分组匹配 / 反向引用
    JavaScript函数之作用域 / 作用链域 / 预解析
    JavaScript正则表达式实例汇总
    python+unittets框架
    locust简介
    seleniumselenium各种技巧,滑动,提示框,窗口大小,iframe切换等等
    selenium 定位元素的方式
    jmeter环境配置,配置中文环境,原理-1
    appium环境搭建+真机+获取package和activity来验证是否搭建成功+appium自带的定位元素
  • 原文地址:https://www.cnblogs.com/mmlz/p/6059741.html
Copyright © 2011-2022 走看看