Topic Portal
1 /*2 Test Instructions: Arranges the first string arbitrarily so that there is no more than A/b string appearing3 string processing/greed: Brute force finds the maximum non-overwriting a string and then dynamically obtains the optimal solution in the B string4 I 'm sick of it, I originally wanted to output up to a, then the most B, but it is not guaranteed to be the most: (5 */6#include <cstdio>7#include <cstring>8#include <string>9#include <iostream>Ten#include <algorithm> One#include <cmath> A using namespacestd; - - Const intMAXN = 1e5 +Ten; the Const intINF =0x3f3f3f3f; - CharS[MAXN], A[MAXN], B[MAXN]; - intcnt_s[ -], cnt_a[ -], cnt_b[ -]; - intlen_s, Len_a, Len_b; + - intMainvoid)//codeforces Round #307 (Div. 2) B. Zgukistringz + { A //freopen ("b.in", "R", stdin); at - while(SCANF ("%s", s) = =1) - { -scanf ("%s", a); scanf ("%s", b); -len_s = strlen (s); Len_a = strlen (a); Len_b =strlen (b); - inmemset (cnt_s,0,sizeof(cnt_s)); -memset (Cnt_a,0,sizeof(cnt_a)); tomemset (Cnt_b,0,sizeof(Cnt_b)); + - for(intI=0; i<len_s; ++i) cnt_s[s[i]-'a']++; the for(intI=0; i<len_a; ++i) cnt_a[a[i]-'a']++; * for(intI=0; i<len_b; ++i) cnt_b[b[i]-'a']++; $ Panax Notoginseng intAns_a =0, Ans_b =0;inttot =100000; - for(intI=0; i< -; ++i) {if(cnt_a[i]) tot = min (tot, cnt_s[i]/cnt_a[i]);} the for(intI=0; i<=tot; ++i) + { A intp =100000; the for(intj=0; j< -; ++J) {if(Cnt_b[j]) p = min (P, (cnt_s[j]-I * cnt_a[j])/cnt_b[j]);} + if(i + p > ans_a + ans_b) {ans_a = i; Ans_b =p;} - } $ $ for(intI=1; i<=ans_a; ++i) printf ("%s", a); - for(intj=1; j<=ans_b; ++J) printf ("%s", b); - for(intI=0; i< -; ++i) the { - for(intj=1; j<=cnt_s[i]-ans_a*cnt_a[i]-ans_b*cnt_b[i]; ++j)Wuyiprintf ("%c",'a'+i); the } -Puts (""); Wu } - About return 0; $}
String processing/greedy codeforces Round #307 (Div. 2) B. Zgukistringz