• <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>

            Ural 1060 Flip Game

            C++ Accepted
            0.031 197 KB


            1060. Flip Game

            Time Limit: 2.0 second
            Memory Limit: 16 MB
            Flip game is played on a rectangular 4×4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the other one is black and each piece is lying either it's black or white side up. Each round you flip 3 to 5 pieces, thus changing the color of their upper side from black to white and vice versa. The pieces to be flipped are chosen every round according to the following rules:
            1. Choose any one of the 16 pieces.
            2. Flip the chosen piece and also all adjacent pieces to the left, to the right, to the top, and to the bottom of the chosen piece (if there are any).
            Problem illustration
            Consider the following position as an example:
            bwbw
                        wwww
                        bbwb
                        bwwb
                        
            Here "b" denotes pieces lying their black side up and "w" denotes pieces lying their white side up. If we choose to flip the 1st piece from the 3rd row (this choice is shown at the picture), then the field will become:
            bwbw
                        bwww
                        wwwb
                        wwwb
                        
            The goal of the game is to flip either all pieces white side up or all pieces black side up. You are to write a program that will search for the minimum number of rounds needed to achieve this goal.

            Input

            The input consists of 4 lines with 4 characters "w" or "b" each that denote game field position.

            Output

            Write to the output a single integer number — the minimum number of rounds needed to achieve the goal of the game from the given position. If the goal is initially achieved, then write 0. If it's impossible to achieve the goal, then write the word "Impossible" (without quotes).

            Sample

            input output
            bwbw
                        wwww
                        bbwb
                        bwwb
                        
            Impossible
                        
            Problem Source: 2000-2001 ACM Northeastern European Regional Programming Contest

            wa了幾次
            原因:1是cnt只增沒(méi)減
                         2是search的推出條件寫成if(m==16){ ……},這種情況下對(duì)于只改變最后一個(gè)即可得情況沒(méi)有判定。改成m>16

            #include<iostream>
            using namespace std;
            bool status[6][6]={0};
            const int MAX=0x7fffffff;
            int cnt=0,cntMin=MAX;        

            bool check()
            {
                
            bool f=status[1][1];
                
            int i,j;
                
            for(i=1; i<=4; i++)
                
            for(j=1; j<=4; j++)
                   
            if(f!=status[i][j])return false;
                
                
            return true;
            }

            void turn(int i, int j)
            {
                 status[i][j]
            =!status[i][j];
                 status[i
            -1][j]=!status[i-1][j];
                 status[i
            +1][j]=!status[i+1][j];
                 status[i][j
            -1]=!status[i][j-1];
                 status[i][j
            +1]=!status[i][j+1];
            }

            void input()
            {
                 
            char ch;
                 
            for(int i=1; i<=4; i++)
                 
            for(int j=1; j<=4; j++)
                 {
                         cin
            >>ch;
                         status[i][j]
            =(ch=='b' ? 0 : 1 );
                 }


            void search(int m)
            {
                    
            if(m>16){
                             
            if( check() && (cnt<cntMin) )cntMin=cnt;     
                             
            return ;
                    }
                    
            int i=(m+3)/4
                    
            int j=m-4*(i-1);
                    
                    turn(i,j); cnt
            ++;
                    search(m
            +1);
                    
                    turn(i,j);cnt
            --;
                    search(m
            +1);   
            }

            int main()
            {
                input();   
                search(
            1);
                
            if(cntMin==MAX)cout<<"Impossible"<<endl;
                
            else cout<<cntMin<<endl;
                system(
            "pause");
                
            return 0;
            }

            posted on 2010-07-31 21:44 田兵 閱讀(312) 評(píng)論(0)  編輯 收藏 引用 所屬分類: URAL

            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(2)

            隨筆分類(65)

            隨筆檔案(65)

            文章檔案(2)

            ACM

            搜索

            積分與排名

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            粉嫩小泬无遮挡久久久久久| 99热精品久久只有精品| 亚洲午夜无码AV毛片久久| 奇米影视7777久久精品人人爽| 99久久国产宗和精品1上映 | 99久久精品无码一区二区毛片 | 中文字幕亚洲综合久久2| 久久久久久毛片免费看| 久久永久免费人妻精品下载| 精品国产青草久久久久福利 | 蜜臀久久99精品久久久久久小说| 国产ww久久久久久久久久| 亚洲午夜久久久久妓女影院| 久久国产精品视频| 狠狠色丁香久久婷婷综合五月| 久久久国产一区二区三区| 国产V亚洲V天堂无码久久久| 国产免费久久精品99re丫y| 国产一级做a爰片久久毛片| 色欲综合久久中文字幕网 | 天天躁日日躁狠狠久久| 亚洲AⅤ优女AV综合久久久| 91精品国产综合久久香蕉| 7777久久亚洲中文字幕| 久久天天躁狠狠躁夜夜躁2O2O| 久久综合久久美利坚合众国 | 狠狠色婷婷久久综合频道日韩| 国产精品内射久久久久欢欢| 久久er热视频在这里精品| 午夜人妻久久久久久久久| 精品国产99久久久久久麻豆 | 久久SE精品一区二区| 久久精品人妻中文系列| 久久精品国产99国产精品导航| 国产精品久久久久久久人人看| 久久久久久A亚洲欧洲AV冫| 久久精品一区二区三区中文字幕| 伊人久久精品线影院| 精品久久久久久无码中文野结衣| 91精品无码久久久久久五月天| 国产成人无码精品久久久免费|