SDUT 2608:Alice and Bob
来源:互联网 发布:电影cms解析收费 编辑:程序博客网 时间:2024/06/05 16:07
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
输出
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大学生程序设计竞赛
#include <iostream>#include <math.h>#include <algorithm>using namespace std;int a[55];int kk[55];long long sum,summ;void solve(long long p,int n){ if(p>summ) { sum=0; return; } sum=1; for(int i=n-1; i>=0; i--) { if(p>=kk[i])sum=(sum*a[i])%2012,p-=kk[i]; if(p==0)break; } if(p!=0)sum=0;}int main(){ int N; cin>>N; while(N--) { int n; cin>>n; for(int i=0; i<n; i++) { cin>>a[i]; kk[i]=pow(2,i); summ+=kk[i]; } int k; cin>>k; while(k--) { long long p; cin>>p; solve(p,n); cout<<sum<<endl; } } return 0;}
1 0
- SDUT 2608:Alice and Bob
- SDUT 2608-Alice and Bob(数学题)
- sdut 2608 Alice and Bob (二进制)
- sdut 2608 Alice and Bob 二进制
- 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
- hdu4111 Alice and Bob
- Alice and Bob
- 1798[Bob and Alice]
- Alice and Bob 数学题
- Alice and Bob
- XTU_1168 Alice and Bob
- HTML页面之间跳转传值
- datatables 带查询条件java服务端分页处理
- 轉:Android HAL實例解析
- JS调用OC简单实例-传递一个或者多个参数给oc方法
- java中几种JSON库的解析速度对比
- SDUT 2608:Alice and Bob
- Linux下网卡phy状态检测与控制
- Android Studio报错 Gradle DSL method not found: 'apply()'
- Android动画
- Windows8下安装Docker
- [Poj 2486] Apple Tree 树形DP
- 不同平台上的不同数据类型
- 利用反射构建mongodb操作基础类
- Android模拟器Genymotion使用介绍