△2013山东省ACM竞赛-Alice and Bob

Alice and Bob


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.

 

Sample
Input

1
2
2 1
2
3
4

Sample
Output

2
0

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

题目大意:多项式相乘,写几项就发现规律了。

(a0x+1)(a1x^2+1)(a2x^4+1)

=a0a1a2x^7+a1a2x^6+a0a2x^5+a2x^4+a0a1x^3+a1x^2+a0x+1
   列出来后发现正好该数化为二进制(不用逆置),如果为1,则相乘

7:a0a1a2  
即1+2+4

6:a1a2    
 即2+4

5:a0a2    
 即1+4

4:a2      
  即4

3:a0a1    
即1+2

2:a1      
 即2

1:a0      
 即1

0:1

可以看出,对应为:

a3   a2   a1
  a0

8     4  
  2     1


 1 #include <iostream>
2 #include<cstdio>
3 #include<string.h>
4 using namespace std;
5
6 #define maxn 105
7
8 int a[maxn],pos[maxn];
9
10 int main()
11 {
12 int t,n,i,j,q,ans;
13 long long p;//因为0 <= p <= 1234567898765432
14 scanf("%d",&t);
15 while(t--)
16 {
17 scanf("%d",&n);
18 memset(a,0,sizeof(a));//这个很妙,比如n=3,则p>=8以后都要=0,就靠这一句
19 for(i=0;i<n;i++)
20 {
21 scanf("%d",&a[i]);
22 }
23 scanf("%d",&q);
24 while(q--)
25 {
26 scanf("%lld",&p);
27 if(p==0)
28 {
29 printf("1\n");//别忘了
30 continue;
31 }
32 memset(pos,0,sizeof(pos));
33 i=0;
34 while(p)
35 {
36 pos[i++]=p%2;//求p转化为二进制
37 p/=2;
38 }
39 ans=1;
40 for(j=0;j<i;j++)
41 {
42 if(pos[j])//如果那一位二进制=1
43 {
44 ans=ans*a[j]%2012;//则就是那几位相乘,一边乘一遍取余2012
45 }
46 }
47 printf("%d\n",ans);
48 }
49 }
50 return 0;
51 }

△2013山东省ACM竞赛-Alice and Bob,布布扣,bubuko.com

时间: 2024-10-07 22:50:15

△2013山东省ACM竞赛-Alice and Bob的相关文章

[2013山东省第四届ACM大学生程序设计竞赛]——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). T

第一、三、四届(2010、2012、2013)山东省ACM

第一届山东省赛题目(2400-2409)http://acm.sdibt.edu.cn/JudgeOnline/problemset.php?search=%E5%B1%B1%E4%B8%9C%E7%9C%81%E7%AC%AC%E4%B8%80%E5%B1%8AACM%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E5%A4%A7%E8%B5%9B2010.10.3 第三届山东省赛题目(3240-3249)http://acm.sdibt.edu.cn/JudgeOn

【第七届山东省ACM竞赛】Square Number

思路比较明确,就是一个数,如果和另外一个数乘起来是个平方数的话,那么满足一个条件 数A可以分解成为n1 个 a1,n2 个 a2 -- 数B可以分解成为m1个 a1,m2 个 a2-- 这满足的条件是(ni + mi) % 2 == 0 一个数的分解出来奇个数的因子乘起来得到的值为v,找之前有几个数他的奇个数因子成积为v 代码如下: #include<cmath> #include<cstdio> #include<cstring> #include<iostre

【第六届山东省ACM竞赛】B题 Lowest Unique Price(SDUT3252)

题目链接:Here 这一题是我今年省赛最大的遗憾啊.诶...想想就觉得伤心啊.这一题其实不难,但是比赛时,我已经先到了怎么做,但是由于鄙人的失误,结果导致我们队后两个小时的时间都耗在那里了.越想越觉得可惜啊.我们现在看看这题的思路吧. 这一题,貌似大多人都是有STL的set做的.其实,这一题可以用线段树做(不知道线段树的童鞋请移步:这里),而且还是简单的单点更新问题.不知道单点更新的同学请移步:这里.虽然我做线段树的题目不是很多,但是我发现了一个规律.利用这个规律就可以更好的判断,此题是否为线段

Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

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 as

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)*....

[2013山东ACM省赛] 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

[2013山东省第四届ACM大学生程序设计竞赛]——Rescue The Princess

Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry the princess set out immedia

ACM训练联盟周赛 C题 Alice和Bob的Nim游戏

题目描述 众所周知,Alice和Bob非常喜欢博弈,而且Alice永远是先手,Bob永远是后手. Alice和Bob面前有3堆石子,Alice和Bob每次轮流拿某堆石子中的若干个石子(不可以是0个),拿到所有石子中最后一个石子的人获胜.这是一个只有3堆石子的Nim游戏. Bob错误的认为,三堆石子的Nim游戏只需要少的两堆的石子数量加起来等于多的那一堆,后手就一定会胜利.所以,Bob把三堆石子的数量分别设为 {k,4k,5k}(k>0). 现在Alice想要知道,在k 小于 2^n 的时候,有多