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.

示例输入

1
2
2 1
2
3
4

示例输出

2
0

提示

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转换成一个二进制的数,然后分别乘上系数。
一开始挺难理解的,T给我讲了,才明白了,其实可以在纸上自己先算算再自己写出二进制来,推一下,就可以理解了
 #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
int main()
{
int n ;
cin>>n ;
while(n--)
{
int t ;
int a[],b[] ;
cin>>t ;
memset(a,,sizeof(a));
for(int i = ; i <= t- ; i++)
{
cin>>a[i];
}
int p;
cin>>p;
for(int i = ; i <= p ; i++)
{
long long q ;
cin>>q ;
int x = ;
if(q == )
{
cout<<""<<endl;
continue ;
}
while(q)
{
b[x++] = q% ;
q = q/ ;
}
int sum = ;
for(int j = ; j <= x- ; j++)
{
if(b[j])
{
sum = sum*a[j]%;
}
}
cout<<sum<<endl ;
}
}
return ;
}

2013年山东省第四届ACM大学生程序设计竞赛 Alice and Bob的更多相关文章

  1. Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...

  2. 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server

    点击打开链接 2226: Contest Print Server Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 53  Solved: 18 [Su ...

  3. sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛

    Mountain Subsequences 题目描述 Coco is a beautiful ACMer girl living in a very beautiful mountain. There ...

  4. 2013年山东省第四届ACM大学生程序设计竞赛J题:Contest Print Server

    题目描述     In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code ...

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

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

  6. 山东省第四届ACM大学生程序设计竞赛解题报告(部分)

    2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...

  7. UPC 2224 / “浪潮杯”山东省第四届ACM大学生程序设计竞赛 1008 Boring Counting 主席树

    Problem H:Boring Counting Time Limit : 6000/3000ms (Java/Other)   Memory Limit : 65535/32768K (Java/ ...

  8. [2012山东省第三届ACM大学生程序设计竞赛]——n a^o7 !

    n a^o7 ! 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2413 Time Lim ...

  9. angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems ca ...

随机推荐

  1. 【风马一族_C】进制转化

    #include "stdio.h" #include "Math.h" #define number 50 //设置数组的长度 int num10; //十进 ...

  2. 如何使用NET Reactor为您的.Net(C#,VB.Net) 源代码加密

    前言 VS开发的源代码安全性,是很多开发者头痛的事情.于是保护好源代码便成了开发者们最关心的事情之一了. 在网上搜一搜,很多有不少的第三方工具可以为源代码加密.加密方式不外乎就是混淆,加壳. 理论上, ...

  3. jexus 配置 学习

    http://www.linuxdot.net/ 1.禁止或允许某IP或IP段访问网站 A.只允许某些IP地址访问网站(白名单功能) 默认情况下,允许所有IP地址访问.如果手工设置IP地址白名单, 那 ...

  4. [大牛翻译系列]Hadoop(16)MapReduce 性能调优:优化数据序列化

    6.4.6 优化数据序列化 如何存储和传输数据对性能有很大的影响.在这部分将介绍数据序列化的最佳实践,从Hadoop中榨出最大的性能. 压缩压缩是Hadoop优化的重要部分.通过压缩可以减少作业输出数 ...

  5. php 获取链接参数

    private function getQuerystr($url,$key){        $res = '';        $a = strpos($url,'?');        if($ ...

  6. php获取服务器时间的代码

    php获取服务器时间的代码. 用php的date函数即可来获取服务器上的时间:  <?php //将时区设置为中国 date_default_timezone_set("PRC&quo ...

  7. PHP+AJAX无刷新返回天气预报

    AjaxJavaScript天气预报php天气预报,用php来写一个天气预报的模块. 天气数据是通过采集中国气象网站的.本来中国天气网站也给出了数据的API接口.以下是API的地址.返回的数据格式为j ...

  8. C# 枚举,传入int值返回string值

    需求:1:子公司负责人2:人事3:审批人4:签批人 5:管理员  传入值为1,2,3,4,5这个数字的某一个.需要返回他们的中文描述. 一下忘记该怎么写了...后来百度下查出来了..记录下当个小工具吧 ...

  9. linux 目录

    创建和删除 int mkdir(const char *pathname, mode_t mode); int rmdir(const char *pathname); 另外remove也可以删除文件 ...

  10. Hadoop分布式安装

    一.安装准备         1.下载hadoop,地址:http://hadoop.apache.org/,下载相应版本         2.下载JDK版本:Hadoop只支持1.6以上,地址:ht ...