http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608

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

来源

 2013年山东省第四届ACM大学生程序设计竞赛

示例程序

分析:

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

给出一个多项式:(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1),输入P,求X^p 前边的系数。

将p转换成一个二进制的数,然后分别乘上系数。

AC代码:

 #include<stdio.h>
#include<string.h>
int a[],b[];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,p,i,j;
scanf("%d",&n);
memset(a,,sizeof(a));
for(i=;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&p);
int count,ans;
long long c;
while(p--)
{
count=,ans=;
scanf("%lld",&c);
if(c==)
{
printf("1\n");
continue;
} while(c)
{
b[ans++]=c%;
c/=;
}
for(i=;i<ans;i++)
if(b[i])
{
count=count*a[i]%;
}
printf("%d\n",count);
}
}
return ;
}

官方标程:

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int mod = ;
int a[], n;
int Q;
#define ll long long
ll w[];
#define fuck while(1)
int main() {
int t;
freopen("data.in", "r", stdin);
// freopen("data.out", "w", stdout);
scanf("%d", &t);
w[] = ;
for(int i = ; i < ; i++) w[i] = (w[i - ] << );
while(t--) {
scanf("%d", &n);
if(n <= || n > ) fuck;
memset(a, , sizeof(a));
for(int i = ; i < n; i++) {
scanf("%d", &a[i]);
if(a[i] < || a[i] > ) fuck;
}
scanf("%d", &Q);
while(Q--) {
ll x;
scanf("%I64d", &x);
if(x > 1234567898765432ll) fuck;
int ret = ;
for(int i = ; x; i++, x /= ) {
if((x & )) {
ret = ret * a[i] % mod;
}
}
printf("%d\n", ret);
}
}
return ;
}

数据生成程序:

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <time.h>
using namespace std;
#define ll long long
#define mod 1234567898765432ll
ll r() {
ll a = rand();
a *= rand();
a %= ;
if(a < ) a += ;
return a;
}
ll maxx;
ll rr() {
int xx = rand() % ;
if(xx == ) return ;
return r() * r() % maxx;
}
int main() {
int t = ;
freopen("data.in", "w", stdout);
cout<<t<<endl;
srand(time(NULL));
while(t--) {
int n = rand() % + ;
cout<<n<<endl;
for(int i = ; i < n; i++) {
int a = rand() % ;
if(i) cout<<" ";
cout<<a;
}
maxx = (1ll << (n));
maxx = maxx + maxx / ;
cout<<endl;
int Q = rand() % + ;
ll woca = (1ll << n);
Q = Q % woca + ;
cout<<Q<<endl;
while(Q--) {
cout<<rr() % mod<<endl;
}
}
return ;
}

sdutoj 2608 Alice and Bob的更多相关文章

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

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

  2. SDUT 2608:Alice and Bob

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

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

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

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

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

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

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

  6. hdu 4268 Alice and Bob

    Alice and Bob Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  7. 2014 Super Training #6 A Alice and Bob --SG函数

    原题: ZOJ 3666 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666 博弈问题. 题意:给你1~N个位置,N是最 ...

  8. ACdream 1112 Alice and Bob(素筛+博弈SG函数)

    Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit ...

  9. 位运算 2013年山东省赛 F Alice and Bob

    题目传送门 /* 题意: 求(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1) 式子中,x的p次方的系数 二进制位运算:p ...

随机推荐

  1. C#反射生成简单sql语句

    static void Main(string[] args) { book book = new book();//实体类 booktest b1 = new booktest(); book.bo ...

  2. 转自大楚网:微软SAPI:让你的软件能说会道

    [IT168专稿]“没声音,再好的戏也出不来.”这虽然是一句广告,但是也说出了一个道理,我们所开发的软件,特别是一些多媒体软件,要是能够发 出声音,能说会道,将为我们的软件增添不少光彩.同时,我们面临 ...

  3. 放弃iOS4,拥抱iOS5

      前言 苹果在2011年的WWDC大会上发布了iOS5,不过考虑到要支持iOS4.x的系统,大多数App都无法使用iOS5的新特性.现在将近1年半过去了,从我们自己的App后台的统计数据.一些第三方 ...

  4. CAS单点登录配置

    见http://download.csdn.net/detail/u010786672/6942715下载.

  5. query 的list()和iterator()区别

    区别: 1.返回的类型不一样,list返回List,iterate返回iterator. 2.查询策略不同.(获取数据的方式不一样,list会直接查询数据库,iterate会先到数据库中获取id,然后 ...

  6. PS教程1000例

    http://www.missyuan.com/thread-446934-1-1.html Photoshop绘制逼真头发发丝效果http://www.missyuan.com/thread-446 ...

  7. 数位DP bzoj1026

    1026: [SCOI2009]windy数 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 5809  Solved: 2589[Submit][Sta ...

  8. 演示save point及自治事务的用处

    1.确认数据库版本 2 举一个例子,说明save point的用处,给出SQL演示. 2.1环境准备 save point的作用是通过在事务中间设置检查点,可以更加精细的控制事务,防止一部分操作错误而 ...

  9. Choose Concurrency-Friendly Data Structures

    What is a high-performance data structure? To answer that question, we're used to applying normal co ...

  10. jquery动态刷新select的值,后台传过来List<T>,前台解析后填充到select的option中

    jquery动态刷新select的值:将后台传来的List<T>赋值到select下的option. 第一个select选择后出发该方法refreshMerchant(params),传递 ...