zoukankan      html  css  js  c++  java
  • 2018 徐州 icpc 网络赛 A 递推or数学公式

    After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a Nogaku show during the feast. To enjoy the show, every audience has to wear a Nogaku mask, and seat around as a circle.

    There are N guests Reimu serves. Kokoro has 2^k2k masks numbered from 0,1,cdots,0,1,⋯, 2^k - 12k−1, and every guest wears one of the masks. The masks have dark power of Dark Nogaku, and to prevent guests from being hurt by the power, two guests seating aside must ensure that if their masks are numbered ii and jj , then ii XNOR jj must be positive. (two guests can wear the same mask). XNOR means ~(ii^jj) and every number has kk bits. (11 XNOR 1 = 11=1, 00 XNOR 0 = 10=1, 11 XNOR 0 = 00=0)

    You may have seen 《A Summer Day's dream》, a doujin Animation of Touhou Project. Things go like the anime, Suika activated her ability, and the feast will loop for infinite times. This really troubles Reimu: to not make her customers feel bored, she must prepare enough numbers of different Nogaku scenes. Reimu find that each time the same guest will seat on the same seat, and She just have to prepare a new scene for a specific mask distribution. Two distribution plans are considered different, if any guest wears different masks.

    In order to save faiths for Shrine, Reimu have to calculate that to make guests not bored, how many different Nogaku scenes does Reimu and Kokoro have to prepare. Due to the number may be too large, Reimu only want to get the answer modules 1e9+71e9+7 . Reimu did never attend Terakoya, so she doesn't know how to calculate in module. So Reimu wishes you to help her figure out the answer, and she promises that after you succeed she will give you a balloon as a gift.

    Input

    First line one number TT , the number of testcases; (T le 20)(T≤20) .

    Next TT lines each contains two numbers, NN and k(0<N, k le 1e6)k(0<N,k≤1e6) .

    Output

    For each testcase output one line with a single number of scenes Reimu and Kokoro have to prepare, the answer modules 1e9+71e9+7 .

    样例输入复制

    2
    3 1
    4 2

    样例输出复制

    2
    84

    题目来源

    ACM-ICPC 2018 徐州赛区网络预赛

    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<cstdio>
    #include<cstdlib>
    #include<algorithm>
    const int p=1e9+7; 
    using namespace std;
    typedef long long LL;  
    int n,m,k;
    LL quick_mod(LL a,LL b)
    {
    	LL ans=1;
    	a%=p;
    	while(b)
    	  {
    	  	if(b&1) {ans=ans*a%p;b--;}
    	  	b>>=1;a=a*a%p;
    	  }
    	return ans;
    }
    int main()
    {
    	int T_T,cas=0;
    	scanf("%d",&T_T);
    	while(T_T--)
    	{
    		scanf("%d%d",&n,&m);
    		LL A=quick_mod(2,m);
    		LL ans=A*quick_mod(A-1,n-1)%p,x=A-1,y=1,z=0,t1,t2;
    		for(int i=2;i<=n-2;i++)
    		{
    			t1=(x-y+p)%p;
    			t2=(x-z+p)%p;
    			y=t2;z=t1;
    		  	x=x*(A-1)%p;
    		} 
    		if(n>2)
    		{
    		ans=(ans-A*(x-y)%p)%p;
    		ans=(ans+p)%p;
    	    }//特判
    		printf("%lld
    ",ans);
    	}
    }

     

    另外一种O(t*log(n))的方法:用m种颜色着色圆的n个扇形的方法总数

    偷了一波其它队的代码(wyj,zkq,lzk)

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const ll mod = 1000000007LL;
    
    ll qpow(ll a, ll n) {
    	ll res = 1;
    	while (n)
    	{
    		if (n & 1)
    			res = res * a % mod;
    		a = a * a % mod;
    		n >>= 1;
    	}
    	return res % mod;
    }
    
    int main() {
    	int T;
    	scanf("%d", &T);
    	ll n, k;
    	while (T--)
    	{
    		ll ans = 0;
    		scanf("%lld%lld", &n, &k);
    		ll num = qpow(2, k);
    		ans = qpow(num - 1, n) + (num * qpow(2, mod - 2) % mod - 1) % mod * (1 + qpow(-1, n)) % mod + 1;
    		ans %= mod;
    		//printf("%lf
    ", pow(num - 1, n) + 1 + (num / 2 - 1)*(1 + pow(-1, n)));
    		printf("%lld
    ", (ans + mod) % mod);
    	}
    }
  • 相关阅读:
    Maven报错找不到jre
    SpringBoot学习记(一)第一个SpringBoot Web服务
    (转!)大话websocket
    (转!)Netdata---Linux系统性能实时监控平台部署
    Jmeter(四十三)WebSocket Sampler 和 Ajax Request
    Jmeter(四十二)Jmeter工作原理
    Centos7安装docker(转!)
    es6 数组去重
    数组对象根据某个值相同合并分组
    await在forEach不起作用解决【await is a reserved word】
  • 原文地址:https://www.cnblogs.com/The-Pines-of-Star/p/9878819.html
Copyright © 2011-2022 走看看