Case #1:
3
2
Case #2:
3
4
思路:
首先处理好四个位置的数,然后就是两重暴力,再用一个long long存起状态就OK了。
AC代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
int a[1500][4];
int main()
{
#ifdef zsc
freopen("input.txt","r",stdin);
#endif
int N,n,m,i,j,k;
int ans,Cas=1;
scanf("%d",&N);
while(N--)
{
ans = 0;
vector<ll> ve;
scanf("%d%d",&n,&m);
char str[50];
memset(a,0,sizeof(a));
for(i=0;i<n+m;++i){
scanf("%s",str);
k = 0;
for(j=0;str[j];++j){
if(str[j]=='.')k++;
else a[i][k] = a[i][k]*10+str[j]-'0';
}
}
printf("Case #%d:\n",Cas++);
for(j=0;j<m;++j){
for(i=0;i<n;++i){
ll sum = 0;
for(k=0;k<4;++k)
sum = sum*1000+(a[i][k]&a[n+j][k]);
ve.push_back(sum);
}
sort(ve.begin(),ve.end());
ans = unique(ve.begin(),ve.end())-ve.begin();
printf("%d\n",ans);
ve.clear();
}
}
return 0;
}