首页 > 其他 > 详细

Sdut 2108 Alice and Bob(数学题)(山东省ACM第四届省赛D题)

时间:2014-05-07 23:46:43      阅读:802      评论:0      收藏:0      [点我收藏+]

题目地址:sdut 2608 Alice and Bob

Alice and Bob

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

    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 http://

输出

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

示例输入

122 1234

示例输出

20

提示

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大学生程序设计竞赛

/****************************

题意很简单求一个多项式展开式中 次数为p的项 的系数

算是一道数学题吧,小锐锐觉得是找规律的,模拟赛之后再看这道题,我觉得可以这样理解:

多项式是这样的一个形式(未展开时):

(a0x+1)+(a1x2+1)+ (a2x4  +1)+ (a3x8 + +1)……+ (an-1x2^(n-1) +1) + (anx2^n +1)

这样的项一共n+1项,求展开式中 次数为p的项的系数, 我们可以理解为从上述式子中抽取不定项,使得其次幂之和为p,然后系数呢,就是对应抽取的项的乘积,

然后就是小锐锐说的了,二进制了   

举个例子:比如说3,二进制表示为011,则他就是a0*a1 = 2*1 = 2.

**************************/

Code:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long ll;
int main()
{
    int  t,n,i,j,q,num[100],ans;
    ll p;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        memset(num,0,sizeof(num));
        for(i = 0;i<n;i++)
            scanf("%d",&num[i]);
        scanf("%d",&q);
        while(q--)
        {
            scanf("%lld",&p);  // 这点要注意,一定要是 long long ,不能写 __int64 ,__int64是MFC的,不是ANSC C标准的,貌似sdut 不支持__int64
            j = 0;ans = 1;
            while(p>0)
            {
                if(j>n)
                {
                    ans = 0;break;
                }
                if(p%2)
                    ans*=num[j];
                j++;p/=2;
                ans=ans%2012;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


Sdut 2108 Alice and Bob(数学题)(山东省ACM第四届省赛D题),布布扣,bubuko.com

Sdut 2108 Alice and Bob(数学题)(山东省ACM第四届省赛D题)

原文:http://blog.csdn.net/gray_1566/article/details/25226119

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!