传送门:Problem 3279

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define mem(a,b) (memset(a,b,sizeof a))
const int maxn=+; int m,n;
int tile[maxn][maxn];
int f[maxn][maxn];
int res[maxn][maxn];
int times;
bool isWhite(int x,int y)
{
return (f[x][y]+f[x-][y]+f[x][y+]+f[x][y-]+tile[x][y])%;
}
void Solve()
{
times=-;
mem(res,);
for(int i=;i < (<<n);++i)
{
mem(f,);
int index=n;
int num=i;
/*
for(int j=1;j <= n;++j)
f[1][j]= (i>>(j-1)&1);
*/
do
{
f[][index--]=num%;
num >>= ;
}while(num != && index > );
for(int j=;j <= m;++j)
for(int k=;k <= n;++k)
if(isWhite(j-,k) != )
f[j][k]=; bool flag=false;
for(int k=;k <= n;++k)
if(isWhite(m,k) != )
flag=true;
if(!flag)
{
int cnt=;
for(int j=;j <= m;++j)
for(int k=;k <= n;++k)
cnt += f[j][k];
if(times == - || times > cnt)
{
times=cnt;
memcpy(res,f,sizeof f);
}
}
}
if(times == -)
printf("IMPOSSIBLE\n");
else
for(int i=;i <= m;++i)
for(int j=;j <= n;++j)
printf("%d%c",res[i][j],j == n ? '\n':' ');
}
int main()
{
scanf("%d%d",&m,&n);
for(int i=;i <= m;++i)
for(int j=;j <= n;++j)
scanf("%d",&tile[i][j]);
Solve();
}

poj 3279(开关问题)(待完成)的更多相关文章

  1. POJ.3279 Fliptile (搜索+二进制枚举+开关问题)

    POJ.3279 Fliptile (搜索+二进制枚举+开关问题) 题意分析 题意大概就是给出一个map,由01组成,每次可以选取按其中某一个位置,按此位置之后,此位置及其直接相连(上下左右)的位置( ...

  2. 【枚举】POJ 3279

    直达–>POJ 3279 Fliptile 题意:poj的奶牛又开始作孽了,这回他一跺脚就会让上下左右的砖块翻转(1->0 || 0->1),问你最少踩哪些砖块才能让初始的砖块全部变 ...

  3. POJ 3279(Fliptile)题解

    以防万一,题目原文和链接均附在文末.那么先是题目分析: [一句话题意] 给定长宽的黑白棋棋盘摆满棋子,每次操作可以反转一个位置和其上下左右共五个位置的棋子的颜色,求要使用最少翻转次数将所有棋子反转为黑 ...

  4. POJ 3279 Fliptile(翻格子)

    POJ 3279 Fliptile(翻格子) Time Limit: 2000MS    Memory Limit: 65536K Description - 题目描述 Farmer John kno ...

  5. 状态压缩+枚举 POJ 3279 Fliptile

    题目传送门 /* 题意:问最少翻转几次使得棋子都变白,输出翻转的位置 状态压缩+枚举:和之前UVA_11464差不多,枚举第一行,可以从上一行的状态知道当前是否必须翻转 */ #include < ...

  6. 【POJ 3279 Fliptile】开关问题,模拟

    题目链接:http://poj.org/problem?id=3279 题意:给定一个n*m的坐标方格,每个位置为黑色或白色.现有如下翻转规则:每翻转一个位置的颜色,与其四连通的位置都会被翻转,但注意 ...

  7. Fliptile 开关问题 poj 3279

    Fliptile Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4031   Accepted: 1539 Descript ...

  8. POJ 3279 Fliptile ( 开关问题)

    题目链接 Description Farmer John knows that an intellectually satisfied cow is a happy cow who will give ...

  9. Fliptile POJ - 3279 (开关问题)

    Fliptile Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16483   Accepted: 6017 Descrip ...

随机推荐

  1. tyvjP1288 飘飘乎居士取能量块

    P1288 飘飘乎居士取能量块 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 9月21日,pink生日:9月22日,lina生日:9月23日,轮到到飘飘乎居 ...

  2. Percona XtraBackup 完全及增量备份与恢复的方法

    安装及备份.恢复实现 安装:其最新版的软件可从 http://www.percona.com/software/percona-xtrabackup/ 获得.本文基于CentOS6.x的系统,因此,直 ...

  3. windows下 python中报错ImportError: No module named 'requests'

    原因没有安装requests模块, 可以切换到python的安装目录找到 script文件夹 example: 进入cmd窗口切换到上面的目录直接运营下面两个命令中的一个 1. > Path\p ...

  4. metro扁平UI网页组件

    在线演示 本地下载

  5. TensorFlow3学习笔记1

    1.简单实例:向量相加 下面我们通过两个向量相加的简单例子来看一下Tensorflow的基本用法. [1. 1. 1. 1.] + [2. 2. 2. 2.] = [3. 3. 3. 3.] impo ...

  6. nodeJs学习-15 mysql中间件下载与使用、基本用法

    下载mysql中间件(客户端):cnpm install mysql 链接数据库.查询示例: const mysql=require('mysql'); //1.连接 //createConnecti ...

  7. 从零学React Native之07View

    View 组件是React Native最基本的组件.绝大部分其他React Native 组件. View组件的颜色和边框 backgroundColor 键用来指定颜色. RN 0.19版本开始, ...

  8. Java练习 SDUT-2272_Time

    Time Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description Digital clock use 4 digits to e ...

  9. python初识参数

    1. 什么是函数? f(x) = x + 1 y = x + 1 函数是对功能或者动作的封装 2. 函数的语法和定义 def 函数名(): 函数体 调用: 函数名() 3. 关于函数的返回值 retu ...

  10. vb.net机房收费系统——存储过程

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/xdd19910505/article/details/35574125 一.使用背景         ...