题目链接:传送门

题意:

  给你两个集合A,B,任意组合成新的集合C(去重)

  问你最后C集合大小

题解:

  暴力

  组成的新串hash起来

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
typedef unsigned long long ULL;
const long long INF = 1e18+1LL;
const double pi = acos(-1.0);
const int N = 2e3+, M = 1e3+,inf = 2e9;
ULL mod = 10000019ULL;
int n,m;
char a[N][],b[N][];
map<ULL , int > mp;
int ans;
int check(int i,int j) {
ULL now = ;
ULL ps = ;
for(int ii = ; ii < strlen(a[i]); ++ii) {
now = now + ps * (a[i][ii]) ;
ps *= mod;
}
for(int ii = ; ii < strlen(b[j]); ++ii) {
now = now + ps * (b[j][ii]) ;
ps *= mod;
}
if(mp[now]) return ;
else {
ans++;
mp[now] = ;
return ;
}
}
int main() {
int T,cas = ;
scanf("%d",&T);
while(T--) {
mp.clear();
char ch[];
scanf("%d%d",&n,&m);
getchar();
for(int i = ; i <= n; ++i)
gets(a[i]);
for(int i = ; i <= m; ++i)
gets(b[i]);
ans = ;
for(int i = ; i <= n; ++i) {
for(int j = ; j <= m; ++j) {
check(i,j);
}
}
printf("Case %d: %d\n",cas++,ans);
}
return ;
}
05-04 12:48