Pro.ID22862 TitlePicky Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22862 AC29 Submit88 Ratio32.95% 时间&空间限制描述The cows are such picky eaters. Basically, they can be partitioned into three sets: those who will only eat feed type "a", those who will only eat feed type "b", and those who will only eat feed type "c". Farmer John, being the organized fellow that he is, lays out all the feeds in contiguous groups (exemplified below in lower case), one slot for each cow, e.g.: aaaaabbbbbbbbcc The cows, though they are picky eaters, are not organized when they go to the feed troughs. They are liable to line up with their preferences aligned something like this (cows shown in upper case): BACACBACBBCABCBACBA which, of course, does not satisfy very many cows. However unorganized the cows are, they are nevertheless hungry. Since no cow can start eating until all are ready to eat, calculate the minimum number of "swaps" (exchanges of one pair of cows) required to get the cows aligned properly: A's, then B's, then C's. 输入A single line with at least one and as many as 100 cows represented by A, B, and C. No other characters are present (except for the newline at the end, of course). 输出Description The cows are such picky eaters. Basically, they can be partitioned into three sets: those who will only eat feed type "a", those who will only eat feed type "b", and those who will only eat feed type "c". Farmer John, being the organized fellow that he is, lays out all the feeds in contiguous groups (exemplified below in lower case), one slot for each cow, e.g.: aaaaabbbbbbbbcc The cows, though they are picky eaters, are not organized when they go to the feed troughs. They are liable to line up with their preferences aligned something like this (cows shown in upper case): BACACBACBBCABCBACBA which, of course, does not satisfy very many cows. However unorganized the cows are, they are nevertheless hungry. Since no cow can start eating until all are ready to eat, calculate the minimum number of "swaps" (exchanges of one pair of cows) required to get the cows aligned properly: A's, then B's, then C's. Input A single line with at least one and as many as 100 cows represented by A, B, and C. No other characters are present (except for the newline at the end, of course). Output A single line containing the integer that is the minimum number of swaps to reorder the cows correctly. from the order set, as described. Sample Input BBCBACBA Sample Output 4 Source 样例输入BBCBACBA 样例输出4 作者 |