http://poj.org/problem?id=1753

 #include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std; char s[][];
int a[][];
int deep,step,flag;
void inti(int row,int c)
{
a[row-][c]=!a[row-][c];
a[row][c+]=!a[row][c+];
a[row+][c]=!a[row+][c];
a[row][c-]=!a[row][c-];
a[row][c]=!a[row][c];
}
int check()
{
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
if(a[i][j]!=a[][]) return ;
}
}
return ;
}
void dfs(int row,int c,int deep)
{
if(deep==step)
{
flag=check();
return;
}
if(flag||row==) return;
inti(row,c);
if(c<)
dfs(row,c+,deep+);
else
dfs(row+,,deep+); inti(row,c);
if(c<)
dfs(row,c+,deep);
else
dfs(row+,,deep);
return ;
}
int main()
{
memset(a,,sizeof(a));
for(int i=; i<; i++)
{
scanf("%s",s[i]);
}
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
if(s[i][j]=='b')
a[i+][j+]=;
}
}
for(step=; step<=; step++)
{
dfs(,,);
if(flag)
{
printf("%d\n",step);
break;
}
}
if(!flag) printf("Impossible\n");
return ;
}

Flip Game的更多相关文章

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

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

  2. [LeetCode] Flip Game 翻转游戏之二

    You are playing the following Flip Game with your friend: Given a string that contains only these tw ...

  3. [LeetCode] Flip Game 翻转游戏

    You are playing the following Flip Game with your friend: Given a string that contains only these tw ...

  4. poj Flip Game 1753 (枚举)

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27005   Accepted: 11694 Descr ...

  5. POJ1753 Flip Game(bfs、枚举)

    链接:http://poj.org/problem?id=1753 Flip Game Description Flip game is played on a rectangular 4x4 fie ...

  6. poj1753 Flip Game

    题意:4*4的正方形,每个格子有黑白两面,翻转格子使得4*4个格子显示全黑或全白,翻转要求:选中的那个格子,以及其上下左右相邻的格子(如果存在)要同时翻转.输出最小的达到要求的翻转次数或者Imposs ...

  7. java.nio.ByteBuffer中flip,rewind,clear方法的区别

    对缓冲区的读写操作首先要知道缓冲区的下限.上限和当前位置.下面这些变量的值对Buffer类中的某些操作有着至关重要的作用: limit:所有对Buffer读写操作都会以limit变量的值作为上限. p ...

  8. NYOJ:题目529 flip

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=529 由于此题槽点太多,所以没忍住...吐槽Time: 看到这题通过率出奇的高然后愉快的进 ...

  9. Flip Game(dfs)

      Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32384   Accepted: 14142 Des ...

  10. [OpenJudge 3061]Flip The Card

    [OpenJudge 3061]Flip The Card 试题描述 There are N× Ncards, which form an N× Nmatrix. The cards can be p ...

随机推荐

  1. Shell编程速查手册

    https://blog.atime.me/note/shell-scripting-summary.html 总结一下日常Shell脚本里常用的知识,忘记时方便查阅. 常见的shell 常见的Lin ...

  2. iOS 手机淘宝加入购物车动画分析

    1.最终效果 仿淘宝动画 2.核心代码 _cartAnimView=[[UIImageView alloc] initWithFrame:CGRectMake(_propView.frame.size ...

  3. mac 下svn降级

    mac 手欠 homebrew 安装完成后  brew install  svn   svn版本更新至1.8.11 公司svn 不支持1.8  需要降级 搜索很多资料 写的比较麻烦 总结出来是先卸载再 ...

  4. PhalGo-介绍

    PhalGo-介绍 phalgo是一个Go语言的一体化开发框架,主要用于API开发应为使用ECHO框架作为http服务web程序一样可以使用,牛顿曾经说过"如果我比别人看得远,那是因为我站在 ...

  5. 上机实践 - - 一个例子了解C/C++中指针与数组的区别

    本例子来自于<剑指Offer>(P37) 解答如下: size1:20 data1是一个数组,sizeof(data1)是求数组大小. 这个数组包含5个整数,每个整数4个字节,共20字节. ...

  6. U3D 脚本添加和获得对象

    有时候,一开始可能没有对象,而是由于某种触发,产生的一个对象,这里讲解下,如何通过脚本来创建一个对象: 这是通过脚本创建一个立方体: using UnityEngine; using System.C ...

  7. WCF,WebAPI,WCFREST和WebService的区别

    Web ServiceIt is based on SOAP and return data in XML form.It support only HTTP protocol.It is not o ...

  8. (转载)loadrunner简单使用——HTTP,WebService,Socket压力测试脚本编写

    原文出处:http://ajita.iteye.com/blog/1728243/ 先说明一下,本人是开发,对测试不是特别熟悉,但因工作的需要,也做过一些性能测试方面的东西.比较久之前很简单的用过,最 ...

  9. 在企业级开发中使用Try...Catch...会影响效率吗?

    感谢神啊.上帝及老天爷让我失眠,才能够有了本篇文章. 记得不久之前,公司一同事曾经说过:“如果是Winform开发,由于程序是在本地,使用try...catch不会有太大性能问题,可是如果是在web服 ...

  10. 取出当前会话的sid等

    select distinct sess.SID     db_sid,                sess.SERIAL# db_serial#,                process. ...