Flip Game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 29731   Accepted: 12886

Description

Flip game is played on a rectangular 4x4 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).

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

bwwb
bbwb
bwwb
bwww

Sample Output

4

 #include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
using namespace std;
int ans=;
int an[]= {0x13,0x27,0x4e,0x8c,
0x131,0x272,0x4e4,0x8c8,
0x1310,0x2720,0x4e40,0x8c80,
0x3100,0x7200,0xe400,0xc800
};
bool check(int n)
{
if(n==)return ;
n^=0xffff;
if(n==)return ;
return ;
}
void fun(int x,int n,int aa)
{
if(check(n))ans=min(ans,aa);
if(x==)return;
fun(x+,n^an[x],aa+);
fun(x+,n,aa);
}
int main()
{
char a;
int i,j,n=;
for(i=; i<; i++)
{
for(j=; j<; j++)
{
a=getchar();
if(a=='b')
n=(n<<)+;
else n<<=;
}
getchar();
}
fun(,n,);
if(ans!=)
cout<<ans<<endl;
else cout<<"Impossible"<<endl;
}

Flip Game poj 1753的更多相关文章

  1. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  2. 枚举 POJ 1753 Flip Game

    题目地址:http://poj.org/problem?id=1753 /* 这题几乎和POJ 2965一样,DFS函数都不用修改 只要修改一下change规则... 注意:是否初始已经ok了要先判断 ...

  3. POJ 1753 Flip Game(高斯消元+状压枚举)

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45691   Accepted: 19590 Descr ...

  4. [ACM训练] 算法初级 之 基本算法 之 枚举(POJ 1753+2965)

    先列出题目: 1.POJ 1753 POJ 1753  Flip Game:http://poj.org/problem?id=1753 Sample Input bwwb bbwb bwwb bww ...

  5. POJ 1222 POJ 1830 POJ 1681 POJ 1753 POJ 3185 高斯消元求解一类开关问题

    http://poj.org/problem?id=1222 http://poj.org/problem?id=1830 http://poj.org/problem?id=1681 http:// ...

  6. 穷举(四):POJ上的两道穷举例题POJ 1411和POJ 1753

    下面给出两道POJ上的问题,看如何用穷举法解决. [例9]Calling Extraterrestrial Intelligence Again(POJ 1411) Description A mes ...

  7. poj 1753 2965

    这两道题类似,前者翻转上下左右相邻的棋子,使得棋子同为黑或者同为白.后者翻转同行同列的所有开关,使得开关全被打开. poj 1753 题意:有一4x4棋盘,上面有16枚双面棋子(一面为黑,一面为白), ...

  8. OpenJudge/Poj 1753 Flip Game

    1.链接地址: http://bailian.openjudge.cn/practice/1753/ http://poj.org/problem?id=1753 2.题目: 总时间限制: 1000m ...

  9. POJ 1753 Flip Game DFS枚举

    看题传送门:http://poj.org/problem?id=1753 DFS枚举的应用. 基本上是参考大神的.... 学习学习.. #include<cstdio> #include& ...

随机推荐

  1. [2014-08-18]Mac OSX 命令行快捷键

    系统:OSX 10.9.4 将光标移动到行首:ctrl + a 将光标移动到行尾:ctrl + e 清除屏幕: ctrl + l 搜索以前使用命令:ctrl + r 清除当前行: ctrl + u 清 ...

  2. MIPI DSI转LVDS芯片方案TC358775XBG

    型号:TC358775XBG功能:MIPI转LVDS通信方式:IIC/MIPI Command mode分辨率:1920*1080电源:3.3/1.8/1.2封装形式:BGA64深圳长期现货 ,提供技 ...

  3. 前端开发【第2篇:CSS】

    鸡血 样式的属性多达几千个,但别担心,按照80-20原则,常用的也就几十个,你完全可以掌握它. Css初识 HTML的诞生 早期只有HTML的时候为了让HTML更美观一点,当时页面的开发者会把颜色写到 ...

  4. css中使用变量

    2017年3月,微软宣布 Edge 浏览器将支持 CSS 变量.这个重要的 CSS 新功能,所有主要浏览器已经都支持了. 声明css变量的时候,变量名前面要加两根连词线(--).变量名大小写敏感,-- ...

  5. CSS 中的 initial、inherit、unset、revert

    在css中,initial(初始).inherit(继承).unset(未设置).revert(还原)这四个关键字可以应用于所有的CSS属性. initial - 初始默认值.IE不支持 inheri ...

  6. CSS3四个自适应关键字——fill-available、max-content、min-content、fit-content

    前面的话 一般地,有两种自适应:撑满空闲空间与收缩到内容尺寸.CSS3将这两种情况分别定义为'fill-availabel'和'fit-content'.除此之外 ,还新增了更细粒度的'min-con ...

  7. js函数防抖、节流实现

    防抖 Debounce 函数防抖就是,延迟一段时间再执行函数,如果这段时间内又触发了该函数,则延迟重新计算: // 简单实现 function debounce(fn, wait) { let t r ...

  8. 【★】Web精彩实战之<智能迷宫>

    JS精彩实战之<智能迷宫>      ---宝贵编程经验分享会--- hello大家好,这里是Web云课堂,之前的一年里我们经历了Html和CSS的系统攻城,此时的你们已经是做静态(动静结 ...

  9. 团队作业4——第一次项目冲刺 SiStH DaY

    项目冲刺--??? 你以为penta kill以后就没事了嘛,就没得写了吗?你还期待我会给你一个六杀?七杀?别逗了,你以为你玩三国杀呢,做项目这么严肃的事情,怎么能玩笑. 那么我就在这里明明白白地告诉 ...

  10. Git和Github使用

    什么是Git? Git 是一个快速.可扩展的分布式版本控制系统,它具有极为丰富的命令集,对内部系统提供了高级操作和完全访问. 版本控制 简单地说,就是将在本地开发的代码,定时推送到服务器.每一次修改, ...