• 第四届 山东省ACM Alice and Bob


    Alice and Bob

    Time Limit: 1000MS Memory Limit: 65536KB

    Problem Description

        Alice and Bob like playing games very much.Today, they introduce a new game.

        There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1). Then Alice ask Bob Q questions. In the expansion of the Polynomial, Given an integer P, please tell the coefficient of the x^P.

    Can you help Bob answer these questions?

    Input

    The first line of the input is a number T, which means the number of the test cases.

    For each case, the first line contains a number n, then n numbers a0, a1, .... an-1 followed in the next line. In the third line is a number Q, and then following Q numbers P.

    1 <= T <= 20

    1 <= n <= 50

    0 <= ai <= 100

    Q <= 1000

    0 <= P <= 1234567898765432

    Output

    For each question of each test case, please output the answer module 2012.

    Example Input

    122 1234

    Example Output

    20

    Hint

    The expansion of the (2*x^(2^0) + 1) * (1*x^(2^1) + 1) is 1 + 2*x^1 + 1*x^2 + 2*x^3

    Author

     2013年山东省第四届ACM大学生程序设计竞赛


    简单的二进制拆分!!!

    #include <map>
    #include <set>
    #include <list>
    #include <queue>
    #include <stack>
    #include <cmath>
    #include <ctime>
    #include <vector>
    #include <bitset>
    #include <cstdio>
    #include <string>
    #include <numeric>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <algorithm>
    #include <functional>
    using namespace std;
    typedef long long  ll;
    typedef unsigned long long ull;
    
    int dx[4]={-1,1,0,0};
    int dy[4]={0,0,-1,1};//up down left right
    bool inmap(int x,int y,int n,int m)
    {
        if(x<1||x>n||y<1||y>m)
            return false;
        return true;
    }
    int hashmap(int x,int y,int m)
    {
        return (x-1)*m+y;
    }
    
    #define eps 1e-8
    #define inf 0x7fffffff
    #define debug puts("BUG")
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define root 1,26,1
    #define read freopen("in.txt","r",stdin)
    #define write freopen("out.txt","w",stdout)
    #define maxn 105
    #define MOD 2012
    
    int a[maxn];
    int gao(ll p)
    {
        int ans=1;
        for(int i=1;p;++i,p>>=1)
            if(p%2)
                ans=(ans*a[i])%MOD;
        return ans;
    }
    int main()
    {
        //read;
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int n,m;
            scanf("%d",&n);
            memset(a,0,sizeof(a));
            for(int i=1;i<=n;++i)
                scanf("%d",a+i);
            scanf("%d",&m);
            ll p;
            while(m--)
            {
                scanf("%lld",&p);
                printf("%d
    ",gao(p));
            }
        }
        return 0;
    }

  • 相关阅读:
    $('div','li') 和 $('div , li') 和 $('div li') 区别
    javascript代码放在jsp页面中的位置总结
    使用spring @Scheduled注解执行定时任务
    Mybatis学习之与Spring整合
    Mybatis学习之注解
    Mybatis学习之一对多关联查询
    Jenkins Pipeline
    2020-11-22 Windows随笔
    Python BeautifulSoup4合并table单元格
    python call cmd
  • 原文地址:https://www.cnblogs.com/zswbky/p/6717892.html
Copyright © 2020-2023  润新知