vjudge

题意

两个数组\(\{a_i\}\)和\(\{b_i\}\),求从中分别选出两个数或运算结果为\(x\)的方案数。

sol

裸的FWT。

code

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
int x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=0,ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
#define ll long long
const int N = 1<<18;
int T,n,m,q,len;ll a[N],b[N];
int read(){
char s[30];scanf("%s",s);int x=0;
for (int i=0,l=strlen(s);i<l;++i) x=(x<<1)+s[i]-'0';
return x;
}
void fwt(ll *P,int len,int opt){
for (int i=1;i<len;i<<=1)
for (int p=i<<1,j=0;j<len;j+=p)
for (int k=0;k<i;++k)
P[j+k+i]+=P[j+k]*opt;
}
void mul(ll *a,ll *b,int len){
for (int i=0;i<len;++i) a[i]=a[i]*b[i];
}
int main(){
T=gi();
for (int zsy=1;zsy<=T;++zsy){
printf("Case #%d:\n",zsy);
n=gi();m=gi();len=1<<m;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for (int i=1;i<=n;++i) ++a[read()];
for (int i=1;i<=n;++i) ++b[read()];
fwt(a,len,1);fwt(b,len,1);mul(a,b,len);
fwt(a,len,-1);
q=gi();while (q--) printf("%lld\n",a[read()]);
}
return 0;
}

[CSU1911]Card Game的更多相关文章

  1. CSU1911 Card Game 【FWT】

    题目链接 CSU1911 题解 FWT模板题 #include<algorithm> #include<iostream> #include<cstdlib> #i ...

  2. [CSU1911]Card Game(FWT)

    [vjudge-CSU1911] FWT_or #include<cstring> #include<iostream> #include<algorithm> # ...

  3. 【CSU1911】Card Game(FWT)

    [CSU1911]Card Game(FWT) 题面 vjudge 题目大意: 给定两个含有\(n\)个数的数组 每次询问一个数\(x\),回答在每个数组中各选一个数,或起来之后的结果恰好为\(x\) ...

  4. Lesson 3 Please send me a card

    Text Postcards always spoil my holidays. Last summer, I went to Italy. I visited museums and sat in ...

  5. iOS - Card Identification 银行卡号识别

    1.CardIO 识别 框架 GitHub 下载地址 配置 1.把框架整个拉进自己的工程,然后在 TARGETS => Build Phases => Link Binary With L ...

  6. HDOJ 4336 Card Collector

    容斥原理+状压 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  7. Opensuse enable sound and mic card

    Install application pavucontrol Run pavucontrol You will see the configuration about sound card and ...

  8. 进监狱全攻略之 Mifare1 Card 破解

    补充新闻:程序员黑餐馆系统 给自己饭卡里充钱 ,技术是双刃剑,小心,小心! 前言 从M1卡的验证漏洞被发现到现今,破解设备层出不穷,所以快速傻瓜式一键破解不是本文的重点,年轻司机将从本文中获得如下技能 ...

  9. Card(bestcoder #26 B)

    Card Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

随机推荐

  1. JMS、MQ、ActiveMQ

    JMS 的一个标准或者说是一个协议. 通常用于企业级应用的消息传递. 主要有topic 消息(1 对多), queue 消息(1对1). ActiveMQ 是一个JMS 的实现, apache 出的. ...

  2. qt打包问题。启动失败:Application failed to start because platform plugin “windows” is missing

    qt打包启动失败:Application failed to start because platform plugin “windows” is missing 通常的原因是因为没有platform ...

  3. 判断一个对象是否有new

    C++语言中,对象没有空和不空的概念,只有对象指针才有空和不空的概念 判断对象指针是否为空只需要和NULL常量进行比较即可 如果相等,则为空,否则不为空 另外对象虽然没有空和不空的概念,但是有有效和无 ...

  4. 让Tomcat供外网访问

    使用Tomcat+花生壳部署一个Javaweb网站,步骤分为三步. 第一,花生壳配置. 下载花生壳,并默认安装.申请动态域名,激活护照,登录.(都是常规操作,不必多说) 第二,Tomcat设置. 找到 ...

  5. [LnOI2019]加特林轮盘赌(DP,概率期望)

    [LnOI2019]加特林轮盘赌(DP,概率期望) 题目链接 题解: 首先特判掉\(p=0/1\)的情况... 先考虑如果\(k=1\)怎么做到\(n^2\)的时间复杂度 设\(f[i]\)表示有\( ...

  6. C语言结构体初始化的三种方法

    直接上示例了 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 3 ...

  7. IE6+以上清除浮动普遍方法总结

    浮动,CSSfloat属性.学过的人应该知道这个属性,平时用的应该也是很多的.特别是在N栏布局中. 但是我们会经常遇到这样一种情况,前面的元素浮动之后会影响后面的元素,后面的元素需要用清除浮动来消灭前 ...

  8. Oracle索引以及索引碎片

    索引,可以增加查询速度,若没有索引,每次查询都必须是全表查询.例如,搜索某个记录时(如name="gdpuzxs")时,需要全表扫描一下,因为不知道有多少个name="g ...

  9. JQuery -- Validate, Jquery 表单校验

    1. Jquery 表单验证需要插件 jQuery validation 1.7  ---验证插件需要:jQuery 1.3.2 或 1.4.2版本 http://jquery.bassistance ...

  10. 理解Java中字符流与字节流的区别(转)

    1. 什么是流 Java中的流是对字节序列的抽象,我们可以想象有一个水管,只不过现在流动在水管中的不再是水,而是字节序列.和水流一样,Java中的流也具有一个“流动的方向”,通常可以从中读入一个字节序 ...