Test instructions: give you 3 string a,b,c (all made up of lowercase English letters), the need to move the position of the letters within the string A, so that a string b,c the total number of occurrences, and the overlap is not counted.
Idea: First enumerate the number of occurrences of one string (b or C) in a, and then calculate the number of occurrences of the other string in the corresponding case, preserving the maximum total number of times and then.
The code is as follows:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace std;const int N = 1e5+10;int len1, len2, Len3;char A[n], b[n], C[n];int h1[30],h2[30], h3[30];int cnt, CNT2, Cnt3;bool CMP (int a, int b) {return a > B;} int main () {while (~scanf ("%s%s%s", &a, &b, &c)) {GetChar (); len1 = strlen (a); len2 = strlen (b); len3 = strlen (c); for (int i = 0; i < len1; i++) {h1[a[i]-' a '] + +;} for (int i = 0; i < len2; i++) {h2[b[i]-' a '] + +;} for (int i = 0; i < Len3; i++) {h3[c[i]-' a '] + +;} CNT = 0; for (int i=1;; i++) {int p = N; for (int j = 0; J <; J + +) {if (h1[j]-h2[j]*i<0) { P=0; Break }} if (!p) break; int p2 = N; for (int j = 0; J <; J + +) {if (H3[j]) {p2 = min ( P2, (H1[j]-h2[j] * i)/h3[j]); }} if (i+p2>cnt) {cnt = I+P2; Cnt2 = i; Cnt3 = p2; }} for (int i=1;; i++) {int p = N; for (int j = 0; J <; J + +) {if (h1[j]-h3[j] * I < 0) { P=0; Break }} if (!p) break; int p2 = N; for (int j = 0; J <; J + +) {if (H2[j]) {p2 = min ( P2, (H1[j]-h3[j] * i)/h2[j]); }} if (i + p2 > cnt) {cnt = I+P2; Cnt3 = i; Cnt2 = p2; }} for (int i = 0; i < Cnt2; i++) printf ("%s", b); for (int i =0; i < Cnt3; i++) printf ("%s", c); for (int i = 0; i <, i++) {for (int j = 0; J < H1[i]-Cnt2 * h2[i]-cnt3 * H3[i]; j + +) printf ("%c", i+ ' a '); } printf ("\ n"); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 551b:zguki Stringz