• SDUT2608(Alice and Bob)


    题目描述

        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?

    输入

    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

    输出

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

    示例输入

    1
    2
    2 1
    2
    3
    4

    示例输出

    2
    0

    提示

    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

    来源

     2013年山东省第四届ACM大学生程序设计竞赛
     
    #include<stdio.h>
    
    #include<string.h>
    int main()
    {
        long long p,tem,tt;
        int n,q,t,i,k,a[55],sum;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            memset(a,0,sizeof(a));
            for(i=0;i<n;i++)
            scanf("%d",&a[i]);
            scanf("%d",&q);
            while(q--)
            {
                scanf("%lld",&p);
                sum=1;
                while(p>0)
                {
                    k=0;tem=p;tt=1;
                    while(tem)
                    {
                       if(tem>1)tt*=2;
                        k++;tem/=2;
                    }
                    sum=(sum*a[k-1])%2012;
                    p-=tt;
                }
                printf("%d
    ",sum%2012);
            }
        }
    }
    

  • 相关阅读:
    C# 高效字符串连接 StringBuilder介绍
    C#图解教程
    C#中string类型是值类型还是引用类型?
    UML类图10分钟快速入门
    C#设计模式--单例模式
    计算机是如何启动的?
    2018年计划
    转:SQL进阶之变量、事务、存储过程与触发器
    2020/02/06,武汉
    2020/02/06,渐渐,from eason for you for her
  • 原文地址:https://www.cnblogs.com/pangblog/p/3258232.html
Copyright © 2020-2023  润新知