Question:http://poj.org/problem?id=1753
问题点:穷举。
 #include <iostream>
using namespace std;
bool a[][];//记录输入
bool b[][];//记录操作
bool c[][];//中间变量
bool judge()
{
int sum=;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
sum+=c[i][j];
}
}
if(sum==||sum==) return true;
else return false;
}
int inttobools(int k)
{
int cur=;
int count=;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
b[i][j]=k&<<cur++?true:false;
if(b[i][j]) count++;
}
}
return count;
}
void boolscpy()
{
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
c[i][j]=a[i][j];
}
}
}
int main()
{
memset(a,,*sizeof(char));
memset(b,,*sizeof(char));
memset(c,,*sizeof(char));
char ch;
int min=;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
ch=getchar();
if(ch=='w')
a[i][j]=;
else
a[i][j]=;
}
getchar();
}
int s=;
for(int l=;l<;l++)
{
int count=inttobools(l);//转换b[][],并返回其中数字1的数目
if(count>=min) continue;
boolscpy();//赋值给c[][]
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(b[i][j])
{
c[i][j]=!c[i][j];
if(i>) c[i-][j]=!c[i-][j];
if(j>) c[i][j-]=!c[i][j-];
if(i<) c[i+][j]=!c[i+][j];
if(j<) c[i][j+]=!c[i][j+];
}
}
}
if(judge()) {min=count;s=l;}
} if(min==) cout<<"Impossible"<<endl;
else cout<<min<<endl;
return ;
}

北大ACM(POJ1753-Flip Game)的更多相关文章

  1. 北大 ACM 分类 汇总

    1.搜索 //回溯 2.DP(动态规划) 3.贪心 北大ACM题分类2009-01-27 1 4.图论 //Dijkstra.最小生成树.网络流 5.数论 //解模线性方程 6.计算几何 //凸壳.同 ...

  2. 北大ACM - POJ试题分类(转自EXP)

    北大ACM - POJ试题分类 -- By EXP 2017-12-03 转载请注明出处: by EXP http://exp-blog.com/2018/06/28/pid-38/ 相关推荐文: 旧 ...

  3. poj1753 Flip Game(BFS+位压缩)

    题目链接 http://poj.org/problem?id=1753 题意 一个棋盘上有16个格子,按4×4排列,每个格子有两面,两面的颜色分别为黑色和白色,游戏的每一轮选择一个格子翻动,翻动该格子 ...

  4. poj1753,Flip Game,ArrayDeque&lt;Node&gt;

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30449   Accepted: 13232 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. 北大ACM题库习题分类与简介(转载)

    在百度文库上找到的,不知是哪位大牛整理的,真的很不错! zz题 目分类 Posted by fishhead at 2007-01-13 12:44:58.0 -------------------- ...

  8. POJ1753——Flip Game

    Flip Game Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on ...

  9. POJ-1753 Flip Game---二进制枚举子集

    题目链接: https://vjudge.net/problem/POJ-1753 题目大意: 有4*4的正方形,每个格子要么是黑色,要么是白色,当把一个格子的颜色改变(黑->白或者白-> ...

  10. POJ-1753 Flip Game (BFS+状态压缩)

    Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of i ...

随机推荐

  1. Java:浅谈InputStream的close方法

    原则:最好在任何时候使用InputStream或者OutputStream的时候,在finally中调用close()方法,显式关闭. 一个典型的示例 InputStream in = null; t ...

  2. Mysqlbinlog使用

    Mysqlbinlog使用   1.binlog日志打开方法 在my.cnf这个文件中加一行(Windows为my.ini).#vi /etc/my.cnf[mysqld]log-bin=mysqlb ...

  3. Squid 日志详解

    原文地址: http://www.php-oa.com/2008/01/17/squid-log-access-store.html access.log 日志 在squid中access访问日志最为 ...

  4. hibernate一些坑记录集

    1:对比原生sql查询和 hql查询 返回结果的类型 count: sql: select count(0) from xxx where .... 返回 BigInteger hql: select ...

  5. java搭建finagle(1)

    1.新建maven项目 2.pom文件添加依赖 添加3个主要依赖<dependency> <groupId>com.twitter</groupId> <ar ...

  6. Codeforces Round #333 (Div. 2) B. Approximating a Constant Range st 二分

    B. Approximating a Constant Range Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...

  7. BZOJ 3555: [Ctsc2014]企鹅QQ hash

    3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...

  8. delphi 取得汉字的第一个字母

    功能说明://取得汉字的第一个字母 function GetPYIndexChar( hzchar:string):char;begin  caseWORD(hzchar[1])shl8+WORD(h ...

  9. HBuilder:最快的Web开发IDE

    这里给大家介绍一个个人觉得最好用的web开发工具:Hbuilder. HBuilder是DCloud推出的一款支持HTML5的Web开发IDE.快,是HBuilder的最大优势,通过完整的语法提示和代 ...

  10. 读logback源码系列文章(五)——Appender --转载

    原文地址:http://kyfxbl.iteye.com/blog/1173788 明天要带老婆出国旅游几天,所以这段时间暂时都更新不了博客了,临走前再最后发一贴 上一篇我们说到Logger类的inf ...