题目链接:http://poj.org/problem?id=3279

题解:http://www.cnblogs.com/helenawang/p/5538547.html

 /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%lld", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a))
#define lp p << 1
#define rp p << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
const int dx[] = {, , , , -};
const int dy[] = {, , -, , };
int G[maxn][maxn];
int tmp[maxn][maxn];
int ret[maxn][maxn];
int n, m, ans; bool ok(int x, int y) {
return x >= && x < m && y >= && y < n;
} int get(int x, int y) {
int c = G[x][y];
Rep(i, ) {
int xx = x + dx[i];
int yy = y + dy[i];
if(ok(xx, yy)) c += tmp[xx][yy];
}
return c % ;
} int calc() {
For(i, , m) Rep(j, n) if(get(i-, j) != ) tmp[i][j] = ;
Rep(i, n) if(get(m-, i) != ) return -;
int p = ;
Rep(i, m) Rep(j, n) p += tmp[i][j];
return p;
} int main() {
// FRead();
while(~Rint(m) && ~Rint(n)) {
Cls(ret); Cls(tmp); Cls(G); ans = -;
Rep(i, m) Rep(j, n) Rint(G[i][j]);
int nn = << n;
Rep(i, nn) {
Cls(tmp);
Rep(j, n) tmp[][n-j-] = i >> j & ;
int num = calc();
if(num >= && (ans < || ans > num)) {
ans = num;
memcpy(ret, tmp, sizeof(tmp));
}
}
if(ans < ) puts("IMPOSSIBLE");
else {
Rep(i, m) {
Rep(j, n) {
printf("%d%c", ret[i][j], j+==n?'\n':' ');
}
}
}
}
RT ;
}

[POJ3279]Fliptile(开关问题,枚举)的更多相关文章

  1. POJ3279 Fliptile 枚举+简单搜索

    题意:一个矩阵,每个点1或0,然后每次翻一个点,它周围上下左右(包括自己)1->0,0->1,问最少翻几次可以矩阵全是0,忽略题目说的字典序 分析:枚举第一行所有的情况,然后下面几行也随之 ...

  2. POJ--3279(开关问题2个不同时间写的代码)

    Fliptile Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19730   Accepted: 7118 Descrip ...

  3. POJ3279 Fliptile —— 状态压缩 + 模拟

    题目链接:http://poj.org/problem?id=3279 Fliptile Time Limit: 2000MS   Memory Limit: 65536K Total Submiss ...

  4. POJ3279 Fliptile(暴力)

    有一种暴力是这样的,枚举一边,确定另一边. 这一题是这么解的,枚举第一行所有翻转情况,然后剩下几行其实是确定的,因为前i行翻转方式确定后只能通过第i+1行的翻转来改变第i行的状态,于是依次模拟求出剩下 ...

  5. Fliptile 开关问题 poj 3279

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

  6. (简单) POJ 3279 Fliptile,集合枚举。

    Description Farmer John knows that an intellectually satisfied cow is a happy cow who will give more ...

  7. poj-3279 poj-1753(二进制枚举)

    题目链接:http://poj.org/problem?id=3279 题目大意: 有一个m*n的棋盘(1 ≤ M ≤ 15; 1 ≤ N ≤ 15),每个格子有两面分别是0或1,每次可以对一个格子做 ...

  8. POJ-3279.Fliptile(二进制状态压缩 + dfs) 子集生成

    昨天晚上12点刷到的这个题,一开始一位是BFS,但是一直没有思路.后来推了一下发现只需要依次枚举第一行的所有翻转状态然后再对每个情况的其它田地翻转进行暴力dfs就可以,但是由于二进制压缩学的不是很透, ...

  9. poj3279 Fliptile

    思路: 枚举. 枚举了第一行的操作之后,下面每行的操作也随之确定了.因为在确定了第i行的操作之后,要想再改变a[i][j]的状态只能通过改变a[i + 1][j]来实现.另外,用到了集合的整数表示方法 ...

随机推荐

  1. Linux 系统 网络配置

    Linux 系统 网络配置 配置Linux系统网络的方法有几种,这里介绍本人常用的两种. 第一种:使用命令ifconfig配置,具体用法:Ipconfig  ethx   x.x.x.x    net ...

  2. iTween基础之Audio(音量和音调的变化)

    一.基础介绍:二.基础属性 原文地址 : http://blog.csdn.net/dingkun520wy/article/details/50826033 一.基础介绍 AudioTo:改变声音的 ...

  3. C#调用PowerShell的经历

    好久没有写程序了, 再次上手也处于功能强大的Windows PowerShell的缘故. 不多话, 先上段代码引入正题.... static Collection<PSObject> Ru ...

  4. linux作业六——进程的描述和进程的创建

    进程的描述和进程的创建 一.进程描述符task_struct 为了管理进程,内核必须对每个进程进行清晰的描述,进程描述符提供了内核所需了解的进程信息. 代码关键点: 1.Struct list_hea ...

  5. 10.30Daily Scrum

    出席人员 任务分配完成情况 明天任务分配 王皓南 研究代码,讨论实现方法及实现的动能 研究代码,学习相应语言,讨论设计思路 申开亮 研究代码,讨论实现方法及实现的动能 研究代码,学习相应语言,讨论设计 ...

  6. java中判空

    一.概述 java中判等似乎很简单,==用来判断对象引用(内存地址)是否相同,equals用来判断值是否相同.你可以试用String对象轻松区分这一点. 那么在null判等(也就是判空操作)时呢? 可 ...

  7. Linux 操作Mysql详解

    一.引言 想使用Linux已经很长时间了,由于没有硬性任务一直也没有系统学习,近日由于工作需要必须使用Linux下的MySQL.本以为有 Windows下使用SQL Server的经验,觉得在Linu ...

  8. spring @resource @ Autowired

    Spring中什么时候用@Resource,什么时候用@service 当你需要定义某个类为一个bean,则在这个类的类名前一行使用@Service("XXX"),就相当于讲这个类 ...

  9. NData BUG 记录

    一.collection 如果设计如下页面 页面模型如下 using UnityEngine; using System.Collections; using System.Collections.G ...

  10. POJ 1734

    #include<iostream> #include<stdio.h> #define MAXN 105 #define inf 123456789 using namesp ...