http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550

很久都没补这题,最近想学网络流,就看看,队友以前用网络流过的,Orz,

但是这题只需要简单的判断,可能想起来有点麻烦。

考虑一定要从A串取出n个,B串也一定要取出n个,那么A和C的交集一定要大于等于n,同理B。

同时为了得到C串,还需要A + B和C的交集一定要大于等于n * 2

怎么说呢。可以画个图表示下,反正找不到反例。就先码一波。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = ;
char str[maxn], sub1[maxn], sub2[maxn];
int hasStr[], hasSub1[], hasSub2[];
void work() {
int lenstr = strlen(str + );
memset(hasStr, , sizeof hasStr);
memset(hasSub1, , sizeof hasSub1);
memset(hasSub2, , sizeof hasSub2);
for (int i = ; i <= lenstr; ++i) hasStr[str[i]]++;
for (int i = ; i <= lenstr; ++i) hasSub1[sub1[i]]++;
for (int i = ; i <= lenstr; ++i) hasSub2[sub2[i]]++;
int ans1 = , ans2 = , ans3 = ;
for (int i = 'A'; i <= 'Z'; ++i) {
ans1 += min(hasStr[i], hasSub1[i]);
ans2 += min(hasStr[i], hasSub2[i]);
ans3 += min(hasStr[i], hasSub1[i] + hasSub2[i]);
}
if (ans1 < lenstr / || ans2 < lenstr / || ans3 < lenstr) {
printf("NO\n");
} else printf("YES\n");
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
while (scanf("%s%s%s", sub1 + , sub2 + , str + ) > ) work();
return ;
}
05-28 18:24