F(1911)Card Game

Description

Alice and Bob now love to play a card game. Everyone is starting n cards, each card has no more than m attribute. Now they need finish Q tasks, each task will require everyone to give a card, and then make up the attribute types that the task demands (e.g. the task required attributes A, B, C, Alice’s card contains A B and Bob’s card contains B, C. they can use this union to finish the task).
For each task, How many ways that Alice and Bob can do this task.

Input

here are T cases. (T<=20) (about 5 test cases n>=1000 m>=12 Q>=1000)
For each test case.The first line contains two integers n,m(n<=100000, m<=18), which indicates the number of cards which each one has and total attributes.
The next line contain n binary numbers indicates the cards Alice has. The ith binary number m_i indicates the attributes each card have. (m_i <2^18)
(if m_i = 10011 , this card has the first, second and fifth attrtbutes)
The next line contain n binary numbers indicates the cards Bob has.
Then contain one integer Q which is the number of Tasks.
Then next Q lines, each contain one binary number q_i which indicates the attributes they need to make. (qi < 2^18)

Output

For each test case, you first output one line “Case #%d:”
Then output q lines, each line contains one which indicates the ways they can finish this task.

Sample Input

1
4 4
1001 11 1100 1000
1110 1001 10 100
2
1100
111

Sample Output

Case #1:
2
1

Hint


题意:应该就是二进制的或运算吧

思路:用普通的写法,怎么改都被T了,然后复制了标程的fwt.(快速沃尔什变换?我目前也不知道是什么,把问题留着吧)

#include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn=1<<18;
ll a[maxn],b[maxn];
char tmp[20];
// 快速沃尔什变换???????
void fwt(ll *A,int n){
    for(int k=1;k<n;k<<=1){
        int len=k<<1;
        for(int j=0;j<n;j+=len){
            for(int i=0;i<k;i++){
                int x=A[i+j],y=A[i+j+k];
                A[i+j+k]=x+y; //or
            }
        }
    }
}
void ufwt(ll *A,int n){
    for(int k=1;k<n;k<<=1){
        int len=k<<1;
        for(int j=0;j<n;j+=len){
            for(int i=0;i<k;i++){
                int x=A[i+j],y=A[i+j+k];
                A[i+j+k]=y-x; // or
            }
        }
    }
}
int main(){
    int t,cas=0;scanf("%d",&t);
    while(t--){
        int n,m,q,len;scanf("%d%d",&n,&m);
        int tot=1<<m;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=0;i<n;i++){
            scanf("%s",tmp);
            len=strlen(tmp);
            int e=0;
            for(int j=0;j<len;j++){
                e<<=1;
                e|=(tmp[j]-'0');
            }
            a[e]++;
           // cout<<a[i]<<endl;
        }
        for(int i=0;i<n;i++){
            scanf("%s",tmp);
            len=strlen(tmp);
            int e=0;
            for(int j=0;j<len;j++){
                e<<=1;
                e|=(tmp[j]-'0');
            }
            b[e]++;
           // cout<<b[i]<<endl;
        }
        fwt(a,tot); fwt(b,tot);
        for (int i = 0; i < tot; i++) a[i] = a[i]*b[i];
        ufwt(a,tot);
        scanf("%d",&q);
        cout<<"Case #"<<++cas<<":"<<endl;
        while(q--){
            int e=0;scanf("%s",tmp);
            len=strlen(tmp);
            for(int i=0;i<len;i++){
                e<<=1;
                e|=(tmp[i]-'0');
            }
            printf("%lld\n",a[e]);
        }
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以帮您解答这个问题。 首先,我们需要定义一个 Card 类,用于表示一张扑克牌。Card 类需要包含属性 suit(花色)和 rank(点数),以及方法用于获取和设置这些属性。 ```python class Card: def __init__(self, suit, rank): self.suit = suit self.rank = rank def get_suit(self): return self.suit def get_rank(self): return self.rank def __str__(self): return f"{self.rank} of {self.suit}" ``` 接下来,我们需要定义一个 Deck 类,用于表示一副扑克牌。Deck 类需要包含一组 Card 对象,以及方法用于初始化、洗牌和抽牌。 ```python import random class Deck: def __init__(self): self.cards = [] for suit in ["Hearts", "Diamonds", "Clubs", "Spades"]: for rank in range(1, 14): self.cards.append(Card(suit, rank)) def shuffle(self): random.shuffle(self.cards) def deal_card(self): return self.cards.pop() def __str__(self): return f"Deck with {len(self.cards)} cards" ``` 然后,我们需要定义一个 Player 类,用于表示一个玩家。Player 类需要包含一个手牌,以及方法用于添加和移除牌。 ```python class Player: def __init__(self, name): self.name = name self.hand = [] def add_card(self, card): self.hand.append(card) def remove_card(self, card): self.hand.remove(card) def __str__(self): return f"{self.name} has {len(self.hand)} cards" ``` 最后,我们需要定义一个 Game 类,用于表示一个扑克牌游戏。Game 类需要包含一个 Deck 对象和一组 Player 对象,以及方法用于发牌和判断胜负。 ```python class Game: def __init__(self, players): self.deck = Deck() self.players = players def deal_cards(self): for _ in range(2): for player in self.players: card = self.deck.deal_card() player.add_card(card) def determine_winner(self): winner = None highest_score = 0 for player in self.players: score = sum(card.get_rank() for card in player.hand) if score > highest_score: winner = player highest_score = score return winner def play(self): self.deck.shuffle() self.deal_cards() winner = self.determine_winner() print(f"{winner.name} wins with a score of {sum(card.get_rank() for card in winner.hand)}") ``` 这样,我们就完成了一个简单的扑克牌游戏,包括 Card、Deck、Player 和 Game 类。您可以根据自己的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值