青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

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只增沒減
             2是search的推出條件寫成if(m==16){ ……},這種情況下對于只改變最后一個即可得情況沒有判定。改成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 田兵 閱讀(328) 評論(0)  編輯 收藏 引用 所屬分類: URAL

<2010年6月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

導(dǎo)航

統(tǒng)計

常用鏈接

留言簿(2)

隨筆分類(65)

隨筆檔案(65)

文章檔案(2)

ACM

搜索

積分與排名

最新隨筆

最新評論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲福利在线看| 欧美成人伊人久久综合网| 免费短视频成人日韩| 欧美激情综合网| 亚洲精品美女91| 亚洲免费观看高清完整版在线观看| 欧美成人激情视频免费观看| 亚洲第一中文字幕在线观看| 亚洲午夜久久久久久久久电影院| 亚洲第一精品在线| 久久精选视频| 亚洲精品久久久久| 日韩香蕉视频| 欧美在线免费看| 亚洲美女视频| 亚洲国产老妈| 影音先锋成人资源站| 欧美激情精品| 国产女主播一区二区三区| 亚洲一区在线播放| 亚洲欧美怡红院| 亚洲欧洲免费视频| 一区二区成人精品| 欧美剧在线观看| 午夜精品视频在线观看| 亚洲欧美成人精品| 欧美调教视频| 欧美日韩综合在线| 夜夜嗨av一区二区三区| 国产一区二区三区免费观看| 午夜一区二区三区不卡视频| 在线视频亚洲欧美| 免费在线播放第一区高清av| 亚洲免费av网站| 免费av成人在线| 99这里只有久久精品视频| 一区二区三区 在线观看视| 欧美精品粉嫩高潮一区二区| 宅男噜噜噜66国产日韩在线观看| 欧美在线网址| 国产自产在线视频一区| 激情久久久久久久| 亚洲电影免费观看高清完整版在线| 亚洲视屏一区| 亚洲综合成人婷婷小说| 亚洲人成在线观看| 国产精品一区二区久久精品| 狂野欧美一区| 久久久精品午夜少妇| 亚洲黄色有码视频| 久久综合国产精品| 老巨人导航500精品| 另类激情亚洲| 欧美成人在线影院| 亚洲女人天堂av| 欧美激情四色| 久久天堂成人| 久久都是精品| 91久久国产综合久久| 午夜精品久久久久久久| 极品少妇一区二区三区精品视频 | 在线视频亚洲欧美| 亚洲成色777777女色窝| 国产亚洲va综合人人澡精品| 国产欧美日韩视频在线观看| 国产资源精品在线观看| 激情久久综艺| 亚洲欧洲视频在线| 日韩亚洲综合在线| 亚洲系列中文字幕| 亚洲综合日韩在线| 鲁大师影院一区二区三区| 欧美成人黑人xx视频免费观看| 新狼窝色av性久久久久久| 欧美亚洲视频| 亚洲免费高清视频| 在线视频一区观看| 一区二区三区视频观看| 男女激情视频一区| 欧美日韩国产一区精品一区| 美国十次成人| 国产欧美大片| 亚洲欧美另类国产| 香蕉免费一区二区三区在线观看| 亚洲欧洲一区二区在线播放| 亚洲少妇诱惑| 亚洲女人小视频在线观看| 欧美日韩国产综合一区二区| 国产精品视频大全| 精品999在线播放| 亚洲欧美激情在线视频| 亚洲精品日韩精品| 欧美在线一二三| 欧美日韩色婷婷| 久久国产精品久久国产精品| 日韩视频免费观看高清在线视频 | 国产欧美韩日| 一区二区三区日韩| 欧美一级专区免费大片| 在线欧美日韩国产| 在线一区二区三区四区| 欧美一区二区视频观看视频| 国产精品久久久久久久久久三级 | 欧美日韩国产精品专区| 亚洲国产欧美不卡在线观看 | 男同欧美伦乱| 欧美日韩视频专区在线播放| 一区二区日本视频| 午夜久久美女| 国产欧美在线观看| 亚洲破处大片| 激情婷婷亚洲| 亚洲深夜激情| 国产亚洲激情视频在线| 老鸭窝91久久精品色噜噜导演| 国产精品美女诱惑| 免费一级欧美片在线观看| 国产精一区二区三区| 亚洲黄色成人久久久| 狂野欧美激情性xxxx欧美| 国产亚洲欧洲997久久综合| 欧美在线关看| 午夜国产精品视频| 在线一区二区三区四区| 亚洲色在线视频| 一级日韩一区在线观看| 欧美在线999| 欧美一区午夜精品| 欧美人与性动交cc0o| 欧美电影免费观看高清| 国产精品女主播一区二区三区| 亚洲国产一区二区三区在线播| 亚洲国产91精品在线观看| 久久av资源网站| 久久国产精品亚洲77777| 国产精品v亚洲精品v日韩精品| 欧美一区二区三区四区视频| 欧美肉体xxxx裸体137大胆| 亚洲福利一区| 亚洲精品视频在线| 国产亚洲精品久久久久久| 亚洲欧美日韩高清| 亚洲视频网在线直播| 久久中文字幕一区| 日韩写真在线| 亚洲激情在线| 国产精品麻豆va在线播放| 久久久xxx| 欧美~级网站不卡| 日韩一级欧洲| 精品电影在线观看| 国产午夜久久久久| 亚洲三级视频| 国产日韩欧美在线播放| 久久在线免费观看视频| 欧美高清你懂得| 欧美一区二区视频97| aa级大片欧美三级| 一本色道久久综合亚洲精品按摩 | 亚洲精品中文字幕有码专区| **性色生活片久久毛片| 欧美激情一区二区三区在线视频| 老司机免费视频一区二区三区| 在线一区免费观看| 亚洲看片网站| 午夜精品久久久久久久99樱桃| 在线精品福利| 极品尤物av久久免费看| 黄色精品免费| 亚洲精品乱码久久久久久日本蜜臀 | 久久精品一区二区国产| 亚洲国产日本| 欧美一级午夜免费电影| 亚洲日韩欧美视频一区| 一区二区毛片| 欧美一区二区黄色| 欧美69wwwcom| 欧美福利视频一区| 欧美一区成人| 国产精品久久一卡二卡| 国产综合网站| 欧美激情一区在线| 欧美大片18| 亚洲黄色有码视频| 亚洲欧美日韩一区在线| 欧美中文在线观看国产| 麻豆成人精品| 欧美国产日韩精品| 亚洲激情社区| 久久免费的精品国产v∧| 久久综合久色欧美综合狠狠| 欧美黄色大片网站| 亚洲一区黄色| 久久久久国产一区二区三区| 国产精品毛片高清在线完整版| 国模套图日韩精品一区二区| 亚洲激情专区| 亚洲日韩欧美视频一区| 欧美精品入口| 亚洲免费不卡|