2021牛客暑期多校训练营4 C、LCS
LCS
https://ac.nowcoder.com/acm/contest/11255/C
题目大意
你需要构造个长度为的字符串,并且保证。
Solution
考点:模拟
我们先不考虑输出顺序,只考虑是否能够构建,我们把变成的形式进行一次排序。
那么我们可以想到下图这样的构建方式是最合理的:
接下来就是找出最小的字母,然后确定这三个字符串的位置了。
int solve() { string s1, s2, s3; int a = read(), b = read(), c = read(), n = read(); int maxi = max({ a,b,c }); int mini = min({ a,b,c }); int tmp = a ^ b ^ c ^ maxi ^ mini; if (maxi + tmp - mini > n) { return puts("NO"), 0; } if (mini == b) { for (int i = 1; i <= b; ++i) { s1 += 'a', s2 += 'a', s3 += 'a'; } for (int i = 1; i <= a - b; ++i) { s1 += 'b', s2 += 'b'; } for (int i = 1; i <= c - b; ++i) { s1 += 'c', s3 += 'c'; } while (s1.size() < n) s1 += 'd'; while (s2.size() < n) s2 += 'e'; while (s3.size() < n) s3 += 'f'; } else if (mini == c) { for (int i = 1; i <= c; ++i) { s1 += 'a', s2 += 'a', s3 += 'a'; } for (int i = 1; i <= a - c; ++i) { s1 += 'b', s2 += 'b'; } for (int i = 1; i <= b - c; ++i) { s2 += 'c', s3 += 'c'; } while (s1.size() < n) s1 += 'd'; while (s2.size() < n) s2 += 'e'; while (s3.size() < n) s3 += 'f'; } else if (mini == a) { for (int i = 1; i <= a; ++i) { s1 += 'a', s2 += 'a', s3 += 'a'; } for (int i = 1; i <= b - a; ++i) { s2 += 'b', s3 += 'b'; } for (int i = 1; i <= c - a; ++i) { s1 += 'c', s3 += 'c'; } while (s1.size() < n) s1 += 'd'; while (s2.size() < n) s2 += 'e'; while (s3.size() < n) s3 += 'f'; } cout << s1 << endl; cout << s2 << endl; cout << s3 << endl; return 1; }
2021牛客暑期多校训练营 文章被收录于专栏
))补题-ing