zoukankan      html  css  js  c++  java
  • 2016弱校联盟十一专场10.7(12点场) D (poj 3734)

    题目链接:

    https://acm.bnu.edu.cn/v3/contest_show.php?cid=8507#problem/D

    Description

    Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent boy, he starts to think of a math problem of painting. Suppose there are N blocks in a line and each block can be paint red, blue, green or yellow. For some myterious reasons, Panda want both the number of red blocks and green blocks to be even numbers. Under such conditions, Panda wants to know the number of different ways to paint these blocks. 

    Input

    The first line of the input contains an integer T(1≤T≤100), the number of test cases. Each of the next T lines contains an integer N(1≤N≤10^9) indicating the number of blocks. 

    Output

    For each test cases, output the number of ways to paint the blocks in a single line. Since the answer may be quite large, you have to module it by 10007. 

    Sample Input

    2
    1
    2

    Sample Output

    2
    6

     Hint:

    题意:

    给你一个长为n的直线,在直线上看可以放4种不同颜色的砖块,有红,绿,蓝,黄,其中红和绿的砖块的数量必须是偶数个(0也算是偶数),求放置这些砖块的方法的总数。

    题解:

    自己本来准备写dp的,但是队友比较给力,直接把公式给推了出来,就是4^n-1+2^n-1。

    代码:

    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    typedef long long ll;
    #define met(a,b) memset(a,b,sizeof(a));
    #define inf  0x3f3f3f3f
    const int mod  = 10007;
    
    ll q_mul(ll a, ll b, ll mod )
    {
        ll ans = 0;
        while(b)
        {
            if(b & 1)
            {
                b--;
                ans =(ans+ a)%mod;
            }
            b /= 2;
            a = (a + a) % mod;
        }
        return ans;
    }
    
    ll q_pow( ll a, ll b, ll mod )
    {
        ll ans = 1;
        while(b)
        {
            if(b & 1)
            {
                ans = q_mul( ans, a, mod );
            }
            b /= 2;
            a = q_mul( a, a, mod );
        }
        return ans;
    }
    
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            ll n;
            cin>>n;
            ll num1=q_pow(4,n-1,mod);
            ll num2=q_pow(2,n-1,mod);
            ll num3=(num1+num2)%mod;
            cout<<num3<<endl;
        }
    }
    
  • 相关阅读:
    MP4文件格式
    ASP.net 学习路线(详细)
    H.264开源解码器评测
    H264编码 封装成MP4格式 视频流 RTP封包
    MP4介绍与基本AVC编码(x264)教程
    创建一个简单的WCF程序
    VUE 从零开始 学习笔记 一
    关于阿里云短信接口的使用
    对Ul下的li标签执行点击事件——如何获取你所点击的标签
    二逼程序员与苦逼程序员
  • 原文地址:https://www.cnblogs.com/TAT1122/p/5936582.html
Copyright © 2011-2022 走看看