题目描述

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

来源

2013年山东省第四届ACM大学生程序设计竞赛
#include<stdio.h>#include<string.h>
int main()
{long long p,tem,tt;int n,q,t,i,k,a[55],sum;scanf("%d",&t);while(t--){scanf("%d",&n);memset(a,0,sizeof(a));for(i=0;i<n;i++)scanf("%d",&a[i]);scanf("%d",&q);while(q--){scanf("%lld",&p);sum=1;while(p>0){k=0;tem=p;tt=1;while(tem){if(tem>1)tt*=2;k++;tem/=2;}sum=(sum*a[k-1])%2012;p-=tt;}printf("%d\n",sum%2012);}}
}

SDUT2608(Alice and Bob)相关推荐

  1. NYOJ 1053 Alice and Bob (N)

    Alice and Bob (N) 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 也不知道是谁规定的,Alice 和 Bob总是有一堆做不完的事,和一堆奇葩想法,而且重 ...

  2. alice 和 bob 一起 van♂卡牌游戏

    故事背景: 在遥远的 2018 2018 2018年 7 7 7月19" role="presentation" style="position: relati ...

  3. 【安全归约】第一讲 | Definitions定义(算法和安全模型)

    学报网址:卧村密码学报 视频网址:安全归约第一讲 参考教材:<Introduction to security reduction>Fuchun Guo, Willy Susilo, Yi ...

  4. 【CodeForces - 347C 】Alice and Bob (思维,数学,等差数列)

    题干: It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to pl ...

  5. 【UVA - 10891 Game of Sum 】【HRBUST - 1622】 Alice and Bob (区间dp,博弈问题)

    题干: 有一个长度为N的整数序列,Alice和Bob轮流取数,Alice先取.每次玩家只能从左端或者右端 取一个或多个数,但不能两端都取.所有数都被取走后游戏结束,然后统计每个人取走的所有数之和, 作 ...

  6. 密码学中Alice(爱丽丝)和鲍勃(Bob)的历史

    在密码学的文章中,Alice和Bob是出镜率非常高的一对名人,这是为什么呢?本文就其缘由,简单介绍了其相关历史. 爱丽丝(Alice)和 鲍勃(Bob)是世界上最著名的密码学夫妇,有大量的文章都会用他 ...

  7. 2021牛客多校#1 Alice and Bob(博弈论)

    文章目录 题目链接 题目大意 题解 参考代码 总结 题目链接 https://ac.nowcoder.com/acm/contest/11166/A 题目大意 有两堆石头,数量分别为 n,m .两个人 ...

  8. (2021牛客多校一)A.Alice and Bob(博弈)

    样例输入: 5 2 3 3 5 5 7 7 5 7 7 Bob Alice Bob Bob Alice 题意:有两堆石子,石子数目分别为n和m,Alice和Bob轮流进行以下操作: 从一堆石子中取出k ...

  9. HDU 4111 Alice and Bob (博弈)11年成都现场赛

    转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents           by---cxlove 可惜没有机会去现场做,不过当时肯定 ...

最新文章

  1. IBM的“认知计算时代”
  2. 基于JSP实现校园二手交易平台
  3. Scrum之 站立例会
  4. 【对讲机的那点事】节日出游对讲机选择你了解多少?
  5. Maven-学习笔记01【基础-Maven基本概念】
  6. java解压_Java ZIP压缩和解压缩文件(解决中文文件名乱码问题)
  7. 历史是“混合体”,也是“内幕”:说说《三国大传》
  8. 动态规划训练10 [Coloring Brackets CodeForces - 149D]
  9. Spring 实现数据库读写分离
  10. The value of a feed cannot be a tf.Tensor object.
  11. 【数据库系统设计】关系数据库标准语言SQL(3)
  12. fiddler抓包第一课--手机数据抓包
  13. Java之戳中痛点 - (6)避免类型自动转换,例如两个整数相除得浮点数遇坑
  14. SwitchHosts的安装及软件使用
  15. PHPWAMP强行脱离依赖,在系统缺失必备组件或DLL受损的情况下依然能正常运行
  16. 《软件工程之美》打卡第六周
  17. ESP8266固件SDK开发初体验-让ESP8266打印helloworld(基于安信可ESP-07)
  18. Dev C++源代码未编译
  19. Linux下玩转Dota2
  20. iOS9有哪些新特性

热门文章

  1. standard python venv module_python 在venv中报错 ModuleNotFoundError: No module named 'MySQLdb'
  2. python怎么计算时间_python怎么计算若干分钟后是第几天,星期几
  3. 以回调形式使用startActivityForResult方法,并解决Activity被回收的问题
  4. cloc JAVA文件_工具-cloc代码行数统计工具
  5. Matlab实用程序--图形应用-图形的叠加
  6. Python Tensorflow神经网络实现股票预测
  7. php 二维数组字段合并,PHP将二维数组某一个字段相同的数组合并起来的方法,二维数组数组_PHP教程...
  8. python中的input函数怎么用_python input()函数怎么用,_Python_ 少侠科技
  9. java编译器id_JAVA 词法编译器
  10. nodejs常用指令