• 【Henu ACM Round#24 C】Quiz


    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    肯定是这样 先放k-1个,然后空1个,然后再放k-1个。然后再空1个。。 以此类推。

    然后如果(n/k)*(k-1)+n%k>=m的话
    那么答案显然就是m,因为不会出现乘2的情况。

    否则。
    那么只能让某些位置乘2了。
    那么什么地方乘呢?
    肯定是越前面越早乘越好。

    那么temp=m-((n/k)*(k-1)+n%k)就是需要多乘2的次数。
    从左往右放入那n/k个空位置中的前temp个就好

    然后会发现前temp个连续的k块的递推式
    (a_n=2*(a_{n-1}+k))
    其中(a_1=2*k)
    (我在处理的时候把k提取出来了,最后又乘上个k就好
    用高中学的构造方法可以得到an的通项公式为
    (an=k(4*2^{n-1}-2))
    然后把剩下的n/k-temp个k-1块加上去再加上n%k就是答案了
    (2的次方那里要写快速幂

    【代码】

    #include <bits/stdc++.h>
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define all(x) x.begin(),x.end()
    #define pb push_back
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    using namespace std;
    
    const double pi = acos(-1);
    const int dx[4] = {0,0,1,-1};
    const int dy[4] = {1,-1,0,0};
    
    LL n,m,k;
    
    const LL MOD = 1e9 + 9; // 模数
    LL Pow(LL x,LL y){ //求x^y
        LL a = 1;x%=MOD;
        while (y){
            if (y&1) a = (a*x)%MOD;
            x=(x*x)%MOD;
            y>>=1;
        }
        return a;
    }
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
        cin >> n >> m >> k;
        LL temp = (n/k)*(k-1) + n%k;
        if (m<=temp){
            cout<<m<<endl;
        }else{
            LL temp1 = m-temp;
            //还剩n/k个位置
            LL ans = 0;
            ans+=4*Pow(2,temp1-1)-2;
            ans%=MOD;
            ans*=k;
            ans%=MOD;
            ans+=((n/k - temp1)*(k-1)+n%k);
            ans%=MOD;
            cout<<ans<<endl;
        }
    	return 0;
    }
    
    
  • 相关阅读:
    冒泡排序
    pdo 单例类
    php 事物处理
    支付宝支付
    反向代理和负载均衡
    execl导出
    网络层
    OSI 7层 TCP/IP 4层 综合5层
    面试总结
    CMD AMD
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8849411.html
Copyright © 2020-2023  润新知