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. 学习OpenCV——鼠标事件(画框)

    #include "cv.h" #include "highgui.h" bool check_line_state=false; IplImage* work ...

  2. 【Origin】 叹文

    行文如流水, 千字挥手就: 偏偏伤脑筋, 哪得轻松事. -作于二零一五年五月三十日

  3. iis access denied, you do not have permission.

    this kind of problems are usually caused by some IIS configuration issues, like application pool set ...

  4. adb devices 显示error

    1.adb kill-server 2.adb start-server

  5. eclipse批量删除断点(转)

    1.首先调出BreakPoints选项卡(Window--show View--Other--BreakPoints). 2.选择BreakPoints选项卡,选择所有断点,点击删除即可. 

  6. Calculation

    定义一个Strategy接口,其中定义一个方法,用于计算 using System; using System.Collections.Generic; using System.Linq; usin ...

  7. paper 58 :机器视觉学习笔记(1)——OpenCV配置

    开始学习opencv! 1.什么是OpenCV OpenCV的全称是:Open Source Computer Vision Library.OpenCV是一个基于(开源)发行的跨平台计算机视觉库,可 ...

  8. 04---Net基础加强

    字符串常用方法: 属性: Length获取字符串中字符的个数 IsNullOrEmpty()   静态方法,判断为null或者为“” ToCharArray() 将string转换为char[] To ...

  9. c++命名规则

    命名规则根据不同公司有略微不同,这里按照google c++的编程标准1.文件名-全部用小写字母和下划线或横线组成,例如my_useful_class.ccmy-useful-class.ccmyus ...

  10. 夺命雷公狗---node.js---17之项目的构建在node+express+mongo的博客项目2之一,二级路由

    然后我们就来开始搭建后台了... 不过后台我们可以来玩玩他的二级路由... 然后再去修改下他们的样式即可......修改方法和刚才那里的修改方法一样, 访问效果如下所示: OK,已经正常相识了