COJ1911-Card Game
来源:互联网 发布:python字典iteritems 编辑:程序博客网 时间:2024/06/03 20:53
1911: Card Game
Submit Page Summary Time Limit: 3 Sec Memory Limit: 128 Mb Submitted: 51 Solved: 21
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
Source
2017年湖南多校对抗赛第8场
Author
HNU
题目大意:每人有n个至多m位的01串,q次询问,两人各拿出一个01串或运算后形成结果01串的方法数有多少?
解题思路: fwt
#include<iostream>#include<string>#include<stdio.h>#include<string.h>using namespace std;typedef long long LL;const int MAXN=1<<18;int a[MAXN],b[MAXN];char tmp[20];void FWT(int a[],int n){ for(int d=1;d<n;d<<=1) for(int m=d<<1,i=0;i<n;i+=m) for(int j=0;j<d;j++) { int x=a[i+j],y=a[i+j+d]; //xor:a[i+j]=x+y,a[i+j+d]=(x-y+mod)%mod; //and:a[i+j]=x+y; a[i+j+d]=x+y; }}void UFWT(int a[],int n){ for(int d=1;d<n;d<<=1) for(int m=d<<1,i=0;i<n;i+=m) for(int j=0;j<d;j++) { int x=a[i+j],y=a[i+j+d]; //xor:a[i+j]=(x+y)/2,a[i+j+d]=(x-y)/2; //and:a[i+j]=x-y; a[i+j+d]=y-x; }}int main(){ int T,cas=0; scanf("%d",&T); while(T--) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); int n,m,q; scanf("%d%d",&n,&m); int tot=1<<m; for(int i=0;i<n;i++) { scanf("%s",tmp); int len=strlen(tmp); int t=0; for(int j=0;j<len;j++) { t<<=1; t|=(tmp[j]-'0'); } a[t]++; }// for(int i=0;i<=12;i++)// cout<<a[i]<<" ";// cout<<endl; for(int i=0;i<n;i++) { scanf("%s",tmp); int len=strlen(tmp); int t=0; for(int j=0;j<len;j++){ t<<=1; t|=(tmp[j]-'0'); } b[t]++; }// for(int i=0;i<=14;i++)// cout<<b[i]<<" ";// cout<<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); printf("Case #%d:\n",++cas); while(q--) { int t=0; scanf("%s",tmp); int len=strlen(tmp); for(int i=0;i<len;i++) { t<<=1; t|=(tmp[i]-'0'); } printf("%d\n",a[t]); } } return 0;}
- COJ1911-Card Game
- Card Game Beta07
- HDU_A Card Game
- hdu4061 A Card Game
- A. Card Game
- HDU 3722 Card Game
- hdu3722 Card Game (KM)
- HDU 3722 Card Game
- HDU 3722 Card Game
- zoj 3344 Card Game
- CSUOJ1206--Card game
- hdu5494 ( Card Game )
- HDU 5494 Card Game
- HDU 5494 Card Game
- HDU 5494 Card Game
- UVA4260Fortune Card Game【dp】
- HDU 3722 Card Game
- HDU 3722 Card Game
- 计算机科学常见工具书清单、项目开发清单
- Jmeter连接SqlServer数据库进行压力测试
- Servlet笔记
- 查找
- Dubbo异步方法调用里的问题
- COJ1911-Card Game
- Java内部类的使用小结
- C++预科——C语言指针回顾(三) 指针的运算
- poi导出后台提示报错,Minimum column number is 0!
- Websocket个人初见解
- selenium unittest
- hihocoder第九十四周 数论三·约瑟夫问题
- 微服务之微服务架构的优势与不足(一)
- Ubuntu16.04+Anaconda环境下dlib库无法导入解决方法