• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ArcTan

            dfs
            隨筆 - 16, 文章 - 117, 評論 - 6, 引用 - 0
            數據加載中……

            SRM549 DIVⅡ 250pt (概率想法題)

            Problem Statement

                 A magician has invited you to play a game. For this game, the magician uses a special table. On the table there are three spots in a row. The spots are labeled 0, 1, and 2, in order. He places three hats onto the table, so that each hat covers one of the spots. He then takes a ball and places it under one of the hats. The hats are not transparent, so you cannot see the ball while it is under a hat. Next, the magician shuffles the hats by repeatedly swapping two adjacent hats. Each swap is done by sliding the hats along the table, never showing you the ball. Once the magician finishes swapping the hats, you have to guess the spot where the ball is.

            You are given a string hats which describes the contents of the hats in the beginning of the game. The i-th character of hats is 'o' if the ball was initially on the spot i. Otherwise, the i-th character of hats is '.' (a period).

            You are also given a int numSwaps. Assume that the magician swapped the hat that contained the ball exactly numSwaps times. Please remember that in our version of the game the magician always swaps two adjacent hats. Also, note that the total number of swaps in the game may be larger than numSwaps, because the magician may sometimes swap two hats that don't contain the ball.

            Assume that the magician chose the swaps he makes uniformly at random. That is, in each turn with probability 50% he swapped the hats on spots 0 and 1, and with probability 50% he swapped the hats on spots 1 and 2. Return the number of the spot that is most likely to contain the ball at the end of the game. If multiple spots are tied for the largest probability, return the smallest one of them.

            Definition

                
            Class: BallAndHats
            Method: getHat
            Parameters: string, int
            Returns: int
            Method signature: int getHat(string hats, int numSwaps)
            (be sure your method is public)
                

            Notes

            - Two hats are adjacent if their spots differ by 1.

            Constraints

            - hats will contain exactly three characters.
            - hats will contain exactly one 'o' character.
            - hats will contain exactly two '.' characters.
            - numSwaps will be between 0 and 1000, inclusive.

            Examples

            0)
                
            ".o."
            1
            Returns: 0
            The spots 0 and 2 are equally likely to contain the ball after the hat that contains it is swapped once. We return the smallest spot number, which is 0.
            1)
                
            "..o"
            0
            Returns: 2
            The ball does not change spots when 0 swaps are performed; therefore, the ball must be at spot 2.
            2)
                
            "o.."
            1
            Returns: 1

            3)
                
            "..o"
            2
            Returns: 0

            4)
                
            "o.."
            101
            Returns: 1

            This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.




            題意:給三個帽子,一個帽子下面有氣球。一次SWAP可將相鄰的兩個帽子交換。每次SWAP的概率一樣的,0和1,1和2交換的概率都是50%。給出初始狀態,總共有numSwaps次SWAP了帶氣球的帽子。問最后氣球在哪個位置的概率最大,如果有幾個位置,則求最小的位置。

            思路:想法題!numSwaps奇偶性討論分析

            176.5pt  thinking速度太低,多分析分析,鍛煉思維哦!
            #include<string>
            using namespace std;
            class BallAndHats{
            public:
                
            int getHat(string hats, int numSwaps){
                    
            int i=0;
                    
            while (hats[i]!='o')    i++;
                    
            if (numSwaps==0)
                        
            return i;
                    numSwaps
            %=2;
                    
            if (i==0 && numSwaps==0)
                        
            return 0;
                    
            if (i==1 && numSwaps==1)
                        
            return 0;
                    
            if (i==2 && numSwaps==0)
                        
            return 0;
                    
            return 1;
                }
            };




            posted on 2012-07-10 09:03 wangs 閱讀(223) 評論(0)  編輯 收藏 引用 所屬分類: Topcoder

            久久超碰97人人做人人爱| 国产精品久久久久影院嫩草 | 亚洲精品乱码久久久久久蜜桃| 国产精品成人99久久久久91gav| 久久久久久久综合日本| 久久亚洲AV无码精品色午夜| 久久精品亚洲一区二区三区浴池| 国产—久久香蕉国产线看观看| 欧美激情精品久久久久久久九九九 | 日本久久久久久中文字幕| 午夜精品久久久久成人| 国内精品久久久久影院日本| 久久久久亚洲AV成人网人人网站| 久久99精品久久久久久久不卡 | 99久久精品国产一区二区| 久久婷婷五月综合色奶水99啪| 久久精品国产精品亚洲毛片| 老司机午夜网站国内精品久久久久久久久| 色欲综合久久躁天天躁蜜桃 | 97超级碰碰碰久久久久| 亚洲精品无码成人片久久| 亚洲精品97久久中文字幕无码| 人人狠狠综合久久亚洲婷婷| 亚洲精品美女久久777777| 久久久久亚洲AV综合波多野结衣| a高清免费毛片久久| 久久久噜噜噜www成人网| 欧美亚洲国产精品久久久久| 久久精品这里只有精99品| 国产成人精品久久一区二区三区av| 韩国免费A级毛片久久| 久久国产精品成人影院| 久久er99热精品一区二区| 欧洲人妻丰满av无码久久不卡| 久久www免费人成看片| 久久AV高潮AV无码AV| 亚洲精品午夜国产VA久久成人| 午夜天堂精品久久久久| 久久久久99精品成人片试看| 国产精品久久永久免费| 亚洲成色999久久网站|