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. ReentrantLock与synchronized的差别

    总的来说,lock更加灵活. 主要同样点:Lock能完毕synchronized所实现的全部功能 不同: 1.ReentrantLock功能性方面更全面,比方时间锁等候,可中断锁等候,锁投票等,因此更 ...

  2. mybatis0204 一对多查询

    查询所有订单信息及订单下的订单明细信息. sql语句 主查询表:订单表 关联查询表:订单明细 SELECT orders.*, user.username, user.sex , orderdetai ...

  3. shell入门之变量测试 分类: 学习笔记 linux ubuntu 2015-07-10 15:49 31人阅读 评论(0) 收藏

    格式:test 测试条件 字符串测试: 注意空格: test str1 == str2 测试字符串是否相等 test str1 != str2 测试字符串是否不相等 test str1 测试字符串是否 ...

  4. HDFS的Java客户端操作代码(查看HDFS下所有的文件或目录)

    1.查看HDFS下所有的文件或目录 package Hdfs; import java.io.IOException; import java.net.URI; import org.apache.h ...

  5. VS 创建 使用C++ 静态类库(Dll)

    创建静态类库 Walkthrough: Creating and Using a Dynamic Link Library (C++) 1:菜单栏-->File, New, Project. 2 ...

  6. c#迭代算法

    //用迭代算法算出第m个值 //1,1,2,3,5,8...;           //{1,0+1,1+1,1+2,2+3 ,3+5} static void Main(string[]   arg ...

  7. ViewPager和SwipeRefreshLayout之间嵌套使用时发生"事件"冲突

    有时候我们会有一种需求,一个ViewPager有n个页面,每个页面是一个Fragment,在Fragment中使用了具有垂直滑动属性的控件,比如SwipeRefreshLayout!!! 这时二者之间 ...

  8. 如何用visual studio控件(repeater)绑定数据库(SQL server)信息并显示

    今天学习了下如何间接绑定数据库网上看了很多信息,都云里雾里,没有图片说明,初学者完全看不懂,我自己做了一个DEMO,相信可以帮到大家! 一.建立数据库,并构建表信息,我的表信息如下: 表中的数据在数据 ...

  9. mysql出现的错误

    (一)ERROR 1005 (HY000): Can't create table '.\day19\user_role.frm' (errno: 121) 今天遇到的这个问题是因为创建了五张表,其中 ...

  10. 在用VC编译下debug和release的什么区别

    DEBUG和RELEASE 版本差异及调试相关问题:.         内存分配问题 1.          变量未初始化.下面的程序在debug中运行的很好. thing * search(thin ...