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;
    }
    
  • 相关阅读:
    C语言和python分别计算文件的md5值
    C语言计算文件大小
    Linux内核源码下载
    Linux系统编程20_VFS虚拟文件系统
    Linux系统编程19_标准I/O
    C语言Review5_函数指针和数组指针
    C语言Review4_头文件引用符号的区别
    PDO之MySql持久化自动重连导致内存溢出
    小程序之app.json not found
    phpstorm之"Can not run PHP Code Sniffer"
  • 原文地址:https://www.cnblogs.com/mmlz/p/6059741.html
Copyright © 2011-2022 走看看