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

题目地址: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

时间: 2024-11-06 13:23:51

Sdut 2108 Alice and Bob(数学题)(山东省ACM第四届省赛D题)的相关文章

Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)

Crack Mathmen TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 Since mathmen take security very seriously, theycommunicate in encrypted messages. They cipher their texts in this way: for everycharacther c in the message, they replace c wit

acm集训训练赛A题【签到题】

一.题目 Description After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of nhorizontal and m vertical sticks. An intersection point is any point on the grid which is formed by t

acm集训训练赛B题【排序+模拟】

一.原题 Description Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of ndistinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you

(山东省第一届省赛 I 题) SDUTOJ 2159 Ivan comes again! (线段树+set)

题目地址:SDUT 2159 这题的数据很水..几乎所有人都是水过去的..网上也没找到正解,全是水过去的.于是我来第一发正解23333. 首先,可以想到的是先离线下来,然后对行离散化,然后对于每行的所有列用set去存,那么怎么去找最小的行有大于给出列的列数呢?这时候线段树就可以登场了,用线段树来维护每一行的出现的最大列,这样就可以用线段树去搜了.然后删除添加操作同时在set与线段树中完成. 代码如下: #include <iostream> #include <string.h>

2016 acm香港网络赛 F题. Crazy Driver(水题)

原题网址:https://open.kattis.com/problems/driver Crazy Driver In the Linear City, there are N gates arranged in a straight line. The gates are labelled from 1 to N. Between adjacent gates, there is a bidirectional road. Each road takes one hour to travel

2016 acm香港网络赛 B题. Boxes

原题网址:https://open.kattis.com/problems/boxes Boxes There are N boxes, indexed by a number from 1 to N.Each box may (or not may not) be put into other boxes. These boxes together form a tree structure (or a forest structure, to be precise). You have to

2016 acm香港网络赛 C题. Classrooms(贪心)

原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and finding classrooms for orientation activities is always a headache. There are k classrooms on campus and n proposed activities that need to be assigne

2016 acm香港网络赛 A题. A+B Problem (FFT)

原题地址:https://open.kattis.com/problems/aplusb FFT代码参考kuangbin的博客:http://www.cnblogs.com/kuangbin/archive/2013/07/24/3210565.html A+B Problem Given N integers in the range [−50000,50000], how many ways are there to pick three integers ai, aj, ak, such

hihoCoder #1388 : Periodic Signal ( 2016 acm 北京网络赛 F题)

时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal processing. He has a device which can send a particular 1 second signal repeatedly. The signal is A0 ... An-1 under n Hz sampling. One day, the device fell on the ground accidenta