CSU1911 Card Game FWT
Posted mychael
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CSU1911 Card Game FWT相关的知识,希望对你有一定的参考价值。
题目链接
题解
FWT模板题
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define cls(s,v) memset(s,v,sizeof(s))
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = 530005,maxm = 100005,INF = 0x3f3f3f3f;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 1) + (out << 3) + c - 48; c = getchar();}
return flag ? out : -out;
}
inline int RD(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 1) + c - 48; c = getchar();}
return flag ? out : -out;
}
LL A[maxn],B[maxn];
void fwt(LL* a,int n,int f){
for (int i = 1; i < n; i <<= 1)
for (int j = 0; j < n; j += (i << 1))
for (int k = 0; k < i; k++)
a[j + k + i] += a[j + k] * f;
}
int main(){
int T = read();
for (int C = 1; C <= T; C++){
printf("Case #%d:
",C);
int n = read(),m = read(),deg = 1;
cls(A,0); cls(B,0);
while (deg <= (1 << m)) deg <<= 1;
REP(i,n) A[RD()]++;
REP(i,n) B[RD()]++;
fwt(A,deg,1); fwt(B,deg,1);
for (int i = 0; i < deg; i++) A[i] *= B[i];
fwt(A,deg,-1);
int Q = read();
while (Q--) printf("%lld
",A[RD()]);
}
return 0;
}
以上是关于CSU1911 Card Game FWT的主要内容,如果未能解决你的问题,请参考以下文章
AtCoder AISing Programming Contest 2019 Task D. Nearest Card Game
[LeetCode] 822. Card Flipping Game