sdutoj 2608 Alice and Bob
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?
输入
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
提示
来源
示例程序
分析:
给出一个多项式:(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的更多相关文章
- SDUT 2608 Alice and Bob (巧妙的二进制)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Alice and Bob like playing ...
- SDUT 2608:Alice and Bob
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Alice and Bob like playing ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- bzoj4730: Alice和Bob又在玩游戏
Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- hdu 4268 Alice and Bob
Alice and Bob Time Limit : 10000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- 2014 Super Training #6 A Alice and Bob --SG函数
原题: ZOJ 3666 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666 博弈问题. 题意:给你1~N个位置,N是最 ...
- ACdream 1112 Alice and Bob(素筛+博弈SG函数)
Alice and Bob Time Limit:3000MS Memory Limit:128000KB 64bit IO Format:%lld & %llu Submit ...
- 位运算 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 ...
随机推荐
- 【Oracle】同义词问题
优点: 1.节省数据库空间,多用户可以操作同一张表: 2.扩展的数据库的使用范围,能够在不同的数据库用户之间实现无缝交互: 3.利用Database Link.创建同义词可以实现不同数据库服务器之间的 ...
- 【bzoj1367】[Baltic2004]sequence
2016-05-31 17:31:26 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1367 题解:http://www.cnblogs.co ...
- db2工具优化
- 在Javascript中监听flash事件(转)
在Javascript中监听flash事件,其实有两种做法: 1.在特定的环境下(例如专门制作的flash),大家约定一个全局函数,然后在flash的事件中用ExternalInterface.cal ...
- 【JavaService】部署Java jar为Windows后台服务
将Java jar文件部署为Windows后台服务有多种方法:Service Installer.Java service Wrapper.JavaService.exe等等.这里介绍下使用JavaS ...
- PHP 7 测试用例(转)
性能改善:PHP 7高达两倍快的PHP 5.6 显著减少内存使用 抽象语法树 一致的64位支持 改进的异常层次结构 许多转化为异常致命错误 安全随机数发生器 删除旧的和不支持的SAPIs和扩展 空合并 ...
- Android 图片三级缓存
图片缓存的原理 实现图片缓存也不难,需要有相应的cache策略.这里采用 内存-文件-网络 三层cache机制,其中内存缓存包括强引用缓存和软引用缓存(SoftReference),其实网络不算cac ...
- HDU1257
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- bootstrap学习笔记之一
一.概要 bootstrap是最受欢迎的HTML.css和js框架,用于开发响应式布局,移动设备优先的WEB项目. 二.CSS部分 1.bootstrap已经设定了基本的全局样式,如font-fami ...
- 类 class
<?php class Person{ //定义一个类 public $name; //定义属性 public $age; function say(){ //定义办法 echo "m ...