第四届 Alice and Bob
来源:互联网 发布:行业数据网站 编辑:程序博客网 时间:2024/06/07 12:00
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 theexpansion 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
122 1234
Sample 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
我们展开多项式,以下面的为例
就此来看我们可以把P化成二进制形式然后对应的来求
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
long long n,Q,p,A[55];
memset(A,0,sizeof(A));
cin>>n;
for(int i=0;i<n;i++)
cin>>A[i];
cin>>Q;
while(Q--)
{
cin>>p;
int b[10005],c=0,ans=1;
memset(b,0,sizeof(b));
while(p!=0)
{
b[c++]=p%2;
p/=2;
}
for(int i=c-1;i>=0;i--)
{
if(b[i]==1)
{
ans=((ans%2012)*(A[i]%2012))%2012;
}
}
cout<<ans%2012<<endl;
}
}
return 0;
}
- 第四届 Alice and Bob
- 第四届 山东省ACM Alice and Bob
- 2013山东省第四届ACM省赛 Alice and Bob
- 山东省第四届ACM大学生程序设计竞赛 Alice and Bob
- [2013山东省第四届ACM大学生程序设计竞赛]——Alice and Bob
- 第四届acm F题(Alice and Bob)(巧用二进制)
- 2013年山东省第四届ACM大学生程序设计竞赛-Alice and Bob (找规律+二进制)
- 山东省第四届ACM大学生程序设计竞赛-Alice and Bob(二进制&&找规律)
- 山东省第四届ACM省赛题——Alice and Bob(二进制)
- Alice and Bob(山东省第四届ACM大学生程序设计竞赛 )
- Alice and Bob
- 2683. Alice and Bob
- 1798. Alice and Bob
- hdu4268 Alice and Bob
- HDU4268 Alice and Bob
- Alice, Bob and Chocolate
- hdu4268 Alice and Bob
- A:Alice and Bob
- 关于SQL Sever2008导入数据的相关问题
- Unity3D插件之TextMeshPro字体资源的制作
- IOS开发复制的总结(深拷贝浅拷贝区别)
- 三种方式实现多线程同步问题
- leetcode--3Sum Closest
- 第四届 Alice and Bob
- SimpleAdapter中使用Drawable和Bitmap对象的方法
- Jquery 生成 二维码
- String、StringBuffer与StringBuilder之间区别
- android圆形图片
- libsvm python Linux Ubuntu下编程操作实践
- 如何在Fedora 20 KDE 上用使用x11vnc起VNC SERVER共享当前服务器屏幕
- IntelliJ IDEA 14 注册码
- matlab 生成 latex的图 tikz matlab2tikz memory不够用