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. delphi tidhttp 超时的解决方案

    现在delphi都发布到xe10.1了,tidhttp还有缺陷,那就是超时设置在没有网络或者连不上服务器的时候是无效的,不管你设置为多少都要10-20秒.connectTimeout和readTime ...

  2. Groovy新手教程

    Groovy新手教程 kmyhy@126.com  2009-5-13 一.groovy是什么 简单地说,Groovy 是下一代的java语言,跟java一样,它也执行在 JVM 中. 作为跑在JVM ...

  3. Qt 学习之路:输入元素

    前面的章节中,我们看到了作为输入元素的MouseArea,用于接收鼠标的输入.下面,我们再来介绍关于键盘输入的两个元素:TextInput和TextEdit. TextInput是单行的文本输入框,支 ...

  4. U盘安装centos 6.4教程(总算是弄好了

    参考:http://blog.chinaunix.net/uid-27666459-id-3342477.html http://www.linuxidc.com/Linux/2011-05/3569 ...

  5. AndroidStudyDemo之Android4.x介绍

    Android4.x 思维导图 作者:李旺成 时间:2016年4月7日 AndroidStudyDemo 系列篇章开始了!!! AndroidStudyDemo 你值得拥有AndroidStudyDe ...

  6. 基于Html5的兼容所有主流浏览器的在线视频播放器videoJs

    在一个新的项目上需要实现在线视频播放,原本打算借助优酷的视频存储和播放,但是发现这个需要用户注册优酷账户,严重影响用户体验,于是这个方案被毙掉了.于是开始了自己开发一个在线播放器的想法,当然尽量使用已 ...

  7. 自己做的demo--关于HashMap

    package com.pb.collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map ...

  8. 函数返回一个SqlDataReader对象

    解决方法: 1.尝试使用dataset 2.执行数据库操作命令 SqlDataReader reader=mySqlCommand.ExecuteReader(CommandBehavior.Clos ...

  9. android EventBus 的使用

    今天简单的介绍 一下啊 android  EventBus 的使用 EventBus 在官方介绍中是订阅......什么的 一大堆  ,  在我android 菜鸟眼里 就是用来代替android 广 ...

  10. Android Camera 流程梳理

    毕业已经快两年了,一直没有写博客的习惯,这是第一篇,以后要慢慢养成这个习惯.毕业之后一直在做相机,先简单的梳理下Android Camera的流程. Android Camera 是一个client/ ...