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;
        }
    }
    
  • 相关阅读:
    DataSet中的数据全部插入数据库
    SQL养成一个好习惯是一笔财富
    C#不管什么四舍五入,只要是小数取整就得加1
    XMLNode与XmlNodeList
    ASP.NET2.0中配置文件的加密与解密
    编写一个文件目录常用操作的类
    上传文件的方法
    使用javascript 实现.net 验证控件功能
    SQLSERVER如何获取一个数据库中的所有表的名称、一个表中所有字段的名称
    Android之开启内置闹钟与已安装的应用程序设置
  • 原文地址:https://www.cnblogs.com/TAT1122/p/5936582.html
Copyright © 2011-2022 走看看