UPC2222: Alice and Bob
2015-04-07 22:26
218 查看
2222: Alice and Bob
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 263 Solved: 77
[Submit][Status][Web
Board]
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
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^3Source
2013年山东省第四届ACM大学生程序设计竞赛#include<iostream> #include<stack> #include<cstdio> using namespace std; int main() { int t; cin>>t; while(t--) { int n,a[60]; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; int q; cin>>q; while(q--) { stack<int>s; long long p; cin>>p; int x,cnt=-1; int result=1; while(p){ cnt++; x=p%2; s.push(x); p/=2; } if(cnt > n-1){ printf("0\n"); } else{ while(!s.empty()) { if(s.top()==1) { result *= a[cnt]; if(result > 2012) result %= 2012; } s.pop(); cnt--; } printf("%d\n",result); } } } return 0; }后来一直WA,原因就是把stack定义在了外面,会有如果cnt超了,stack里会有剩余的数值,所以每次用都要先定义
相关文章推荐
- hdu 4111 Alice and Bob(博弈)
- ZOJ 3529 A Game Between Alice and Bob 博弈好题
- ZOJ 3529 A Game Between Alice and Bob
- hdu4268 Alice and Bob
- F. Alice and Bob Again
- HDU 4268 Alice and Bob(lower_bound)
- zoj 3757 Alice and Bob and Cue Sports 模拟
- Alice and Bob
- Codeforces Round #201 (Div. 1) A. Alice and Bob(数学)
- UVALive 5088 Alice and Bob's Trip(树形DP)
- zoj 4464 A Game Between Alice and Bob
- HDU 4268 Alice and Bob——STl upper_bound + 贪心
- A. Alice and Bob----最大公约数
- hdu3660 Alice and Bob's Trip 树形dp
- Alice and Bob 数学题
- [2013山东ACM省赛] Alice and Bob
- [2013山东省第四届ACM大学生程序设计竞赛]——Alice and Bob
- 玲珑学院OJ 1029 - Bob and Alice are playing factors (大整数分解)
- HDU4268 Alice and Bob 【贪心】
- ZOJ 3529 - A Game Between Alice and Bob(素因子+博弈)