码迷,mamicode.com
首页 > 其他好文 > 详细

CSU1911 Card Game 【FWT】

时间:2018-07-03 11:59:12      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:algorithm   har   csuoj   ase   names   problems   tchar   vector   \n   

题目链接

CSU1911

题解

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:\n",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\n",A[RD()]);
    }
    return 0;
}

CSU1911 Card Game 【FWT】

标签:algorithm   har   csuoj   ase   names   problems   tchar   vector   \n   

原文地址:https://www.cnblogs.com/Mychael/p/9256724.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!