22862_Picky

2022-5-16 18:23| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-8950728199300-Problem List-采集的数据-后羿采集器.html

Pro.ID

22862

Title

Picky

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22862

AC

29

Submit

88

Ratio

32.95%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    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

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部