翻转棋,注意是翻转周围四个的,不是整行列的  汗-_-!

哥的代码风还是不错的

二进制储存状态

Sample Input

bwwb
bbwb
bwwb
bwww

Sample Output

4
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int n,m,t;
int vis[];
struct node
{
int s,t;
}st;
int flip(int s,int i) //当前的状态,翻第几个棋子
{
int x=i/;
int y=i%;
s^=(<<i); //翻选中的棋子
if(x>) s^=(<<(i-));//翻转上面的
if(y>) s^=(<<(i-));//翻转左边的
if(x<) s^=(<<(i+));//翻转下面的
if(y<) s^=(<<(i+));//翻转右边的
return s;
}
void bfs()
{
node now,next;
vis[st.s]=;
queue<node> q;
q.push(st);
while(!q.empty())
{
now=q.front();
q.pop();
//printf("%d %d\n",now.s,now.t);
if(now.s==||now.s==) //全黑or全白
{
printf("%d\n",now.t);
return;
}
for(int i=;i<;i++)
{
next.s=flip(now.s,i);
next.t=now.t+;
if(!vis[next.s])
{
vis[next.s]=;
q.push(next);
}
}
}
printf("Impossible\n");
return;
}
int main()
{
int i,j,k;
//freopen("1.in","r",stdin);
char s[];
st.s=;
for(i=;i<;i++)
{
scanf("%s",s);
for(j=;j<;j++)
if(s[j]=='b') st.s+=<<(i*+j);
}
memset(vis,,sizeof(vis));
st.t=;
bfs();
return ;
}

poj 1753的更多相关文章

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

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

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

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

  3. 枚举 POJ 1753 Flip Game

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

  4. poj 1753 2965

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

  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 1753 Flip Game(高斯消元+状压枚举)

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

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

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

  8. POJ 1753 (开关问题+高斯消元法)

    题目链接: http://poj.org/problem?id=1753 题目大意:一堆格子,或白或白.每次可以把一个改变一个格子颜色,其上下左右四个格子颜色也改变.问最后使格子全部白或全部黑,求最小 ...

  9. poj 1753 Flip Game 枚举(bfs+状态压缩)

    题目:http://poj.org/problem?id=1753 因为粗心错了好多次……,尤其是把1<<15当成了65535: 参考博客:http://www.cnblogs.com/k ...

  10. OpenJudge/Poj 1753 Flip Game

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

随机推荐

  1. innerText在谷歌、火狐浏览器下的使用

    使用innerHTML.replace(/<.+?>/gim,'')代替innerText,简单正则替换一下

  2. <转>键盘扫描码

    原文链接:http://www.cnblogs.com/wqw/archive/2009/08/30/1556618.html //以下是一个检测按键扫描码的程序 #i nclude <bios ...

  3. 字符串模拟赛T1

    // source code from laekov for c0x17 #define PRID "bxjl" #include <cstdio> #include ...

  4. web_url、web_custom_request、web_submit_data、web_submit_form的使用实例

    业务:根据url获取图片用web_url()函数访问数据;请求方式:HTTP GET 请求;Action(){web_url("imageproxytest", "URL ...

  5. UIImagePickerController详解

    转载自:http://blog.csdn.net/kingsley_cxz/article/details/9157093 1.UIImagePickerController的静态方法: imagep ...

  6. python4delphi 设置syspath

    详细看demo25的代码 These techniques are demonstrated in Demo25 in the examples folder of your Python for D ...

  7. php email邮箱正则验证

    国际域名格式如下: 域名由各国文字的特定字符集.英文字母.数字及“-”(即连字符或减号)任意组合而成, 但开头及结尾均不能含有“-”,“-”不能连续出现 . 域名中字母不分大小写.域名最长可达60个字 ...

  8. hdparm测试硬盘性能

    <1>Centos安装hdparm测试硬盘性能 一.安装hdparm yum install hdparm -y Linux学习,http:// linux.it.net.cn 二.评估读 ...

  9. 尖刀出鞘的display常用属性及css盒模型深入研究

    一:diplay:inline-block 含义:指元素创建了一个行级的块级元素,该元素内部(内容)被格式化成一个块级元素,同时元素本身则被格式化成一个行内元素.更简单的说就是说inline-bloc ...

  10. XPath 定位----光荣之路

    被测试网页的HMTL代码 <html> <body> <div id="div1"> <input name="div1inpu ...