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;
}

SDUT 2608:Alice and Bob的更多相关文章

  1. Alice and Bob(博弈)

    Alice and Bob Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users ...

  2. UOJ #266 【清华集训2016】 Alice和Bob又在玩游戏

    题目链接:Alice和Bob又在玩游戏 这道题就是一个很显然的公平游戏. 首先\(O(n^2)\)的算法非常好写.暴力枚举每个后继计算\(mex\)即可.注意计算后继的时候可以直接从父亲转移过来,没必 ...

  3. 博弈 HDOJ 4371 Alice and Bob

    题目传送门 题意:Alice和 Bob轮流写数字,假设第 i 次的数字是S[i] ,那么第 i+1 次的数字 S[i+1] = S[i] + d[k] 或 S[i] - d[k],条件是 S[i+1] ...

  4. HDU 4268 Alice and Bob(贪心+Multiset的应用)

     题意: Alice和Bob有n个长方形,有长度和宽度,一个矩形能够覆盖还有一个矩形的条件的是,本身长度大于等于还有一个矩形,且宽度大于等于还有一个矩形.矩形不可旋转.问你Alice最多能覆盖Bo ...

  5. SDUT 2608 Alice and Bob (巧妙的二进制)

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Alice and Bob like playing ...

  6. sdutoj 2608 Alice and Bob

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...

  7. 2013年山东省第四届ACM大学生程序设计竞赛E题:Alice and Bob

    题目描述 Alice and Bob like playing games very much.Today, they introduce a new game. There is a polynom ...

  8. 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  9. bzoj4730: Alice和Bob又在玩游戏

    Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...

随机推荐

  1. tooltip

    /* 背景色 ; 字体颜色 ; 云,显示在上面 */ .tooltip-inner{ background-color: #FF0000; ForeColor:#0f0; IsBalloon:true ...

  2. 让show parameter显示隐含参数(11G)

    1.创建视图show_hidden_v$parameter create or replace view show_hidden_v$parameter (INST_ID, NUM , NAME , ...

  3. springframework开源代码导入eclipse

    从毕业到现在已经3个多点年头了,开源框架也用过不少.对于j2ee开发来说,spring框架是是最流行的轻量级可选的框架之一,如果还停留在只会使用,而对源代码不研究是不行的. 话不多说 先从导入代码开始 ...

  4. Java基础之写文件——通过缓冲流写文件(StreamOutputToFile)

    控制台程序,生成一些二进制整型值并且将它们写入到文件中. import java.nio.file.*; import java.nio.*; import java.io.*; public cla ...

  5. Java Axis2 1.6.3+JDK1.7.0_13+Tomcat7.0.65+eclipse搭建web service

    安装文件下载: jdk1.7.0_13 安装步骤参考文章:http://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html tomcat7. ...

  6. 3n+1问题

    猜想: 对于任意大于1的自然数n,若n为奇数,则将n变为3n+1,否则变为n的一半. 经过若干次这样的变换,一定会使n变为1.例如3->10->5->16->8->2-& ...

  7. cookie 使用笔记

    参考书<JSP Web 开发案例教程> index.jsp页面 dologin.jsp页面 welcome.jsp页面 页面显示 点击提交

  8. 现在觉得IT还挺有意思

    前两天刚刚接触编程,用的是C#.开始确实枯燥,但是今天的感觉就好多了,还挺有意思.根据老师讲的课程自己编写了小程序,运行起来还不错.在这里分享下. 关于时间安排的小程序: int sj; int aa ...

  9. oracle索引使用时注意

    1.使用不等于操作符(<>, !=)下面这种情况,即使在列dept_id有一个索引,查询语句仍然执行一次全表扫描 select * from dept where staff_num &l ...

  10. 使用php模拟post的几种方法

    <?phpfunction file_get_contents_post($url,$post){$options=array('http'=>array('method'=>'PO ...