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 ...
随机推荐
- HDU 2825 Wireless Password(AC自动机+DP)
题目链接 做题, #include <cstdio> #include <string> #include <cstring> using namespace st ...
- 【CodeVS】p1038 一元三次方程求解
题目描述 Description 有形如:ax3+bx2+cx+d=0 这样的一个一元三次方程.给出该方程中各项的系数(a,b,c,d 均为实数),并约定该方程存在三个不同实根(根的范围在-100 ...
- 20145330第八周《Java学习笔记》
20145330第八周<Java学习笔记> 第十五章 通用API 通用API 日志:日志对信息安全意义重大,审计.取证.入侵检验等都会用到日志信息 日志API Logger:注意无法使用构 ...
- Node.js的DES加解密和MD5加密
最基本的就是经常用的md5加密算法 代码如下 var MD5=function (data) { var _encrymd5 = require('crypto').createHas ...
- [LintCode] Maximal Rectangle 最大矩形
Given a 2D boolean matrix filled with False and True, find the largest rectangle containing all True ...
- .offsetLeft,.offsetTop
*{ margin:0; padding:0} div {padding: 40px 50px;} #div1 {background: red;} #div2 {background: green; ...
- javaweb实验五
product类: package com.lab;public class Product { private int id; // 商品编号 private S ...
- IIS 注册4.0 Framework
打开cmd ,运行如下命令 C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
- Spring详细总结
Spring的特性之一:IOC(控制反转Inverse Of Control),又称依赖注入,是一种重要的面向对象编程的法则来削减计算机程序的耦合问题 也是轻量级spring框架的核心: 依赖注入: ...
- PNG格式的图像文件,创建的图像的MIME类型的头部
在安装完这三个组件后,还需要重新配置一次PHP,这也是你对采用DSO方式安装PHP感到庆幸的地方之一.运行make clean,然后在当前的配置中添加下面的内容: --with-gd=[/path/t ...