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

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的推出條件寫(xiě)成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 田兵 閱讀(323) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): URAL

<2010年7月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

留言簿(2)

隨筆分類(lèi)(65)

隨筆檔案(65)

文章檔案(2)

ACM

搜索

積分與排名

最新隨筆

最新評(píng)論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲国产网站| 国产午夜精品麻豆| 欧美国产欧美亚洲国产日韩mv天天看完整| 99xxxx成人网| 一区二区三区日韩精品| 亚洲精品乱码久久久久久蜜桃91| 亚洲精品乱码久久久久久久久| 在线亚洲一区二区| 亚洲午夜日本在线观看| 亚洲专区一区| 久久久国产一区二区三区| 久久阴道视频| 亚洲第一福利视频| 亚洲免费观看| 午夜视频久久久| 久久男女视频| 欧美日韩午夜激情| 国产麻豆精品在线观看| 影音先锋日韩有码| 亚洲另类视频| 欧美有码在线视频| 欧美成人一区二区三区在线观看| 欧美激情1区2区| 亚洲小说欧美另类婷婷| 久久久久久97三级| 欧美日韩精品欧美日韩精品一| 国产欧美精品在线观看| 亚洲精品一区中文| 久久精品中文字幕一区| 91久久在线观看| 久久国产日韩| 国产精品久久久爽爽爽麻豆色哟哟 | 欧美一区二区三区婷婷月色| 久久字幕精品一区| 欧美日韩中文字幕在线视频| 激情综合在线| 亚洲欧美在线看| 亚洲国产中文字幕在线观看| 午夜日本精品| 国产精品久久久久久久app| 亚洲二区精品| 欧美一区二区三区免费观看| 欧美国产丝袜视频| 国内精品久久久久国产盗摄免费观看完整版| 亚洲级视频在线观看免费1级| 欧美一区二区三区啪啪| 亚洲美女在线国产| 女人天堂亚洲aⅴ在线观看| 国产亚洲永久域名| 亚洲中字黄色| 日韩一区二区免费看| 老司机一区二区| 国产在线麻豆精品观看| 翔田千里一区二区| 亚洲午夜免费视频| 国产精品成人午夜| 亚洲在线一区二区| 99这里只有精品| 欧美日韩精品综合| 999亚洲国产精| 亚洲国产视频直播| 欧美成人久久| 亚洲男女自偷自拍| 亚洲一区二区三区高清| 亚洲电影免费| 久热国产精品| 亚洲欧洲日本国产| 亚洲高清视频在线观看| 欧美aaaaaaaa牛牛影院| 亚洲日本电影在线| 欧美二区在线播放| 男男成人高潮片免费网站| 亚洲人成网站色ww在线| 亚洲第一主播视频| 欧美劲爆第一页| 一区二区三区黄色| 亚洲天天影视| 国产一区二区三区久久悠悠色av| 久久精品久久综合| 久久久精品免费视频| 亚洲国产日韩在线| 亚洲另类黄色| 国产视频丨精品|在线观看| 久久综合影音| 欧美激情亚洲精品| 午夜精品福利电影| 久久精品视频导航| 亚洲美女免费精品视频在线观看| 99av国产精品欲麻豆| 国产三级精品三级| 欧美国产欧美综合| 欧美日韩一区二区三区在线 | 欧美色精品天天在线观看视频| 亚洲欧美国产精品专区久久| 久久精品官网| 一区二区三区不卡视频在线观看 | 欧美国产日韩精品| 午夜国产欧美理论在线播放| 欧美中文字幕视频在线观看| 欧美体内谢she精2性欧美 | 夜夜夜久久久| 国产在线乱码一区二区三区| 亚洲国产精品成人综合| 国产精品外国| 亚洲片区在线| 一区二区亚洲| 亚洲欧美日产图| 亚洲国产一区二区三区青草影视| 一区二区三区精密机械公司| 伊人久久亚洲美女图片| 亚洲视频在线看| 亚洲日本黄色| 久久久www免费人成黑人精品 | 欧美日韩久久久久久| 久久婷婷蜜乳一本欲蜜臀| 欧美午夜电影完整版| 久久综合影音| 午夜视频一区二区| 欧美日本一区二区三区| 媚黑女一区二区| 国产精品视频内| 亚洲精品日韩在线观看| 亚洲国产精品一区二区www| 亚洲在线视频一区| 一区二区免费在线播放| 久久亚洲欧美| 久久久成人网| 国产手机视频精品| 亚洲一级在线观看| 亚洲午夜日本在线观看| 欧美精品在线播放| 亚洲区在线播放| 亚洲精品一区二区三区婷婷月 | 欧美一区二区三区久久精品茉莉花| 亚洲乱亚洲高清| 欧美承认网站| 亚洲黄色尤物视频| 亚洲欧洲在线一区| 老司机午夜免费精品视频| 欧美成人高清视频| 1769国产精品| 乱中年女人伦av一区二区| 久久久国产午夜精品| 国产亚洲精品aa| 先锋资源久久| 久久久久一区| 亚洲高清免费| 欧美成人dvd在线视频| 欧美激情一区| 日韩亚洲在线观看| 欧美日韩亚洲一区二区三区| 夜夜嗨av一区二区三区四季av| 亚洲天堂成人| 国产精品久久久久久久免费软件 | 亚洲毛片一区二区| 亚洲在线观看视频网站| 国产精品日韩欧美一区| 午夜在线播放视频欧美| 久热国产精品视频| 最近中文字幕日韩精品| 欧美日韩国产综合一区二区| 一区二区日韩精品| 久久av一区| 亚洲国产精品热久久| 欧美日韩国产综合视频在线| 亚洲一区不卡| 麻豆精品国产91久久久久久| 亚洲精选国产| 国产目拍亚洲精品99久久精品| 欧美在线观看一区二区三区| 亚洲大胆美女视频| 久久夜色精品国产欧美乱| 欧美成人免费全部观看天天性色| 亚洲免费观看视频| 国产精品视频观看| 欧美日韩一区在线观看| 欧美日韩高清免费| 午夜视频在线观看一区二区三区 | 亚洲午夜高清视频| 国内精品亚洲| 欧美色中文字幕| 久久综合九色综合欧美狠狠| 99pao成人国产永久免费视频| 久久精品亚洲| 亚洲一线二线三线久久久| 依依成人综合视频| 国产精品三上| 欧美日本亚洲| 美女精品在线| 欧美在线观看www| 中文网丁香综合网| 最新日韩欧美| 欧美a级一区| 久久精品国产99国产精品| 一本色道久久88亚洲综合88| 亚洲国产精品久久久| 国产在线成人| 国产啪精品视频| 国产精品少妇自拍| 欧美日韩在线影院|