[POJ3279]Fliptile(开关问题,枚举)
题目链接: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(开关问题,枚举)的更多相关文章
- POJ3279 Fliptile 枚举+简单搜索
题意:一个矩阵,每个点1或0,然后每次翻一个点,它周围上下左右(包括自己)1->0,0->1,问最少翻几次可以矩阵全是0,忽略题目说的字典序 分析:枚举第一行所有的情况,然后下面几行也随之 ...
- POJ--3279(开关问题2个不同时间写的代码)
Fliptile Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19730 Accepted: 7118 Descrip ...
- POJ3279 Fliptile —— 状态压缩 + 模拟
题目链接:http://poj.org/problem?id=3279 Fliptile Time Limit: 2000MS Memory Limit: 65536K Total Submiss ...
- POJ3279 Fliptile(暴力)
有一种暴力是这样的,枚举一边,确定另一边. 这一题是这么解的,枚举第一行所有翻转情况,然后剩下几行其实是确定的,因为前i行翻转方式确定后只能通过第i+1行的翻转来改变第i行的状态,于是依次模拟求出剩下 ...
- Fliptile 开关问题 poj 3279
Fliptile Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4031 Accepted: 1539 Descript ...
- (简单) POJ 3279 Fliptile,集合枚举。
Description Farmer John knows that an intellectually satisfied cow is a happy cow who will give more ...
- poj-3279 poj-1753(二进制枚举)
题目链接:http://poj.org/problem?id=3279 题目大意: 有一个m*n的棋盘(1 ≤ M ≤ 15; 1 ≤ N ≤ 15),每个格子有两面分别是0或1,每次可以对一个格子做 ...
- POJ-3279.Fliptile(二进制状态压缩 + dfs) 子集生成
昨天晚上12点刷到的这个题,一开始一位是BFS,但是一直没有思路.后来推了一下发现只需要依次枚举第一行的所有翻转状态然后再对每个情况的其它田地翻转进行暴力dfs就可以,但是由于二进制压缩学的不是很透, ...
- poj3279 Fliptile
思路: 枚举. 枚举了第一行的操作之后,下面每行的操作也随之确定了.因为在确定了第i行的操作之后,要想再改变a[i][j]的状态只能通过改变a[i + 1][j]来实现.另外,用到了集合的整数表示方法 ...
随机推荐
- 【UIScrollView】基本方法+基本描述
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(, , , )]; scrollView.backgroundColor = [ ...
- Jquery datatables 重载数据方法
参考这里 { RefreshTable('#table-example', '/BlogManage/GetLabelData'); } function RefreshTable(tableId, ...
- 生鲜电商的O2O之道
- STM32的SPI问题。
问题描述: 之前一直使用的单片机是LPC2109,对其SPI很熟悉.基本就是原本拿来稍作修改就用.由于某种原因需要使用STM32,然后设备的驱动是之前写好的,只修改了一些硬件控制端口,由于硬件驱动使用 ...
- maven学习心得整理
maven的学习心得 已经接触了maven项目有一段时间了,开始时仅仅会使用,在使用中发现了它的强大和方便,于是决心研究一下: 首先,普及一下maven参数: -D:传入属性参数 -P:使用POM中指 ...
- 管道Pipe
管道Pipe java.nio.channels包中含有一个名为Pipe(管道)的类.广义上讲,管道就是一个用来在两个实体之间单向传输数据的导管.管道的概念对于Unix(和类Unix)操作系统的用户来 ...
- IDENTITY属性使用
转自:http://www.cnblogs.com/seusoftware/p/3804333.html 一. 获取IDENTITY列值插入了数据,有时还需要获取刚才生成的序列值另作他用,返回给前端也 ...
- CString向char类型转化 ---“=”: 无法从“wchar_t *”转换为“char *
此文从网上复制过来,原文出处已丢失,望见谅哈 VC 2005中,这个本来很简单的问题又稍微复杂了一点. 在工程里面,一个必不可少的步骤就是把CString转换为shar*字符串.通过 ...
- error: The shader requires a sampler in slot 0 which hasn't been set [XXXsampler]
About the sampler, you need to assign it to your pixelshader. m_d3dContext.Get()->PSSetSamplers(0 ...
- Introduction To Monte Carlo Methods
Introduction To Monte Carlo Methods I’m going to keep this tutorial light on math, because the goal ...