2013年山东省第四届ACM大学生程序设计竞赛E题:Alice and Bob
题目描述
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?
输入
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
输出
示例输入
1
2
2 1
2
3
4
示例输出
2
0
提示
分析:这是一道数学题。简单说来就是给出一堆式子,求x^P 的系数。求公比为2的首项是1的等比数列的和,得到P 的最大值为max(P) = (1 - 2^50) / (1 - 2) = 1125899906842623,而题目中给出P 的输入最大值inputMax(P)为1234567898765432。因此inputMax(P) < 2^51(这保证了下面的程序不会出现数组下标越界的问题)。另外,观察式子不难得出x^P的系数为P 的二进制形式中为1 的部分对应的ai 的乘积。例如对X^11,11写成2进制为(1011)2,那么其系数就是a0*a1*a3。程序如下:
#include<stdio.h>
#include<string.h>
#define MAXN 50
#define MOD 2012
int a[MAXN+];
int main(void)
{
int t, n, q, index, ans;
long long int exp; // 注意定义成int会WA, 因为据题意exp可达1234567898765432这么大 scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
memset(a, , sizeof(a));
for(int i = ; i <= n; i++)
scanf("%d", &a[i]); scanf("%d", &q);
while(q--)
{
scanf("%lld", &exp); // SDUT: C/C++评测程序只支持long long, 不支持int64 ans = index = ;
while(exp)
{
if(exp % != )
ans = (ans*a[index]) % MOD;
index++;
exp /= ;
} printf("%d\n", ans);
} } return ;
}
2013年山东省第四届ACM大学生程序设计竞赛E题:Alice and Bob的更多相关文章
- 2013年山东省第四届ACM大学生程序设计竞赛J题:Contest Print Server
题目描述 In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code ...
- 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server
点击打开链接 2226: Contest Print Server Time Limit: 1 Sec Memory Limit: 128 MB Submit: 53 Solved: 18 [Su ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛
Mountain Subsequences 题目描述 Coco is a beautiful ACMer girl living in a very beautiful mountain. There ...
- 2013年山东省第四届ACM大学生程序设计竞赛 Alice and Bob
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very ...
- 山东省第四届ACM大学生程序设计竞赛解题报告(部分)
2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...
- angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems ca ...
- UPC 2224 / “浪潮杯”山东省第四届ACM大学生程序设计竞赛 1008 Boring Counting 主席树
Problem H:Boring Counting Time Limit : 6000/3000ms (Java/Other) Memory Limit : 65535/32768K (Java/ ...
- 2014年山东省第五届ACM大学生程序设计竞赛F题:Full Binary Tree
题目描述 In computer science, a binary tree is a tree data structure in which each node has at most two ...
随机推荐
- 只要三步!阿里云DLA帮你处理海量JSON数据
概述 您可能有大量应用程序产生的JSON数据,您可能需要对这些JSON数据进行整理,去除不想要的字段,或者只保留想要的字段,或者仅仅是进行数据查询. 那么,利用阿里云Data Lake Analyti ...
- LUOGU P3024 [USACO11OPEN]奶牛跳棋Cow Checkers
题目描述 One day, Bessie decides to challenge Farmer John to a game of ‘Cow Checkers’. The game is playe ...
- C#中使用设置(Settings.settings) Properties.Settings.Default
应用程序及用户设置 在设计时创建新设置的步骤 在“Solution Explorer”(解决方案资源管理器)中,展开项目的“Properties”(属性)节点. 在“Solution Explorer ...
- How To Install Nginx on CentOS 7(转)
How To Install Nginx on CentOS 7 PostedJuly 22, 2014 427.4kviews NGINX CENTOS About Nginx Nginx is a ...
- 面试Nginx的几个常见问题(
1.Nginx 服务器上的 Master 和 Worker 进程分别是什么 Master 进程:读取及评估配置和维持 Worker 进程:处理请求 2.怎么添加模块? Firstly, you h ...
- mysql数据库外键、主键详解
一.什么是主键.外键: 关系型数据库中的一条记录中有若干个属性,若其中某一个属性组(注意是组)能唯一标识一条记录,该属性组就可以成为一个主键 比如 学生表(学号,姓名,性别,班级) 其中每个学生的学 ...
- ajax实例解析
function showHint(str) { var xmlhttp; if (str.length==0) { document.getElementById("txtHint&quo ...
- Java方法传参的问题
1.基本数据类型(byte,short,int,long,float,double,boolean,char)的值传递,不改变其值 2.引用数据类型的值传递,改变其值 3.String类型虽然是引用数 ...
- Python各种转义符
文章来源:https://www.cnblogs.com/luckyplj/p/9792658.html 谢谢作者:雨后观山色
- 系统日志和内核消息 $ dmesg$ less /var/log/messages$ less /var/log/secure$ less /var/log/auth
查看错误和警告消息,比如看看是不是很多关于连接数过多导致? 看看是否有硬件错误或文件系统错误? 分析是否能将这些错误事件和前面发现的疑点进行时间上的比对.