AtCoder Regular Contest 071 C - 怪文書 / Dubious Document
给定一堆字符串,寻找一个字典序最小的字符串,使得该字符串是每个字符串的某个一排列的子串。
感觉这么描述比较诡异,换句话来说就是把每个字符串都切成一堆字符,然后找一个字符串使得切开的字符在每一堆中个数分别相等。
(好像这么描述更迷了)
不过这么描述的话做法也就出来了,开一个桶对于每一个字符串的每一个字符出现次数存储最少的,最后字典序输出。
(好像叫做最长公共无序子序列。。。事实上就是桶排吧。。。)
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cstring> 5 #include <cstdlib> 6 7 using namespace std; 8 9 int n, ch['z' + 1], tmp['z' + 1]; 10 char s[60]; 11 12 int main(){ 13 scanf("%d", &n); 14 memset(ch, 0x3f, sizeof(ch)); 15 while(n --){ 16 scanf("%s", s); 17 memset(tmp, 0, sizeof(tmp)); 18 for(int i = strlen(s) - 1 ; i >= 0 ; i --){ 19 tmp[s[i]] ++; 20 } 21 for(int i = 'a' ; i <= 'z' ; i ++){ 22 ch[i] = min(ch[i], tmp[i]); 23 } 24 } 25 for(int i = 'a' ; i <= 'z' ; i ++){ 26 for(int j = 0 ; j < ch[i] ; j ++){ 27 putchar(i); 28 } 29 } 30 }