[hdu3484]枚举
题意:给两个个01矩阵,有两种操作,(1)交换两列(2)反转某一行。求能否通过若干操作使两矩阵相等
思路:(把所有对B的操作放到A上来,这一定是可以做到一样的效果的)枚举B矩阵的第一列对应A矩阵的第几列,交换这两列,那么根据两个矩阵这一列的相等情况可以确定每一行的操作情况(操作次数实际上只有0和1两种情况),然后根据这个情况确定执行了所有行操作的A矩阵,然后从第二列开始到第m列,依次用A矩阵的某一列(这个也是枚举)去“匹配”B矩阵的当前列,匹配好了那么继续后面的匹配(任何一个可以匹配当前列的列他们是没有区别的,任取一个,所以我们取第一次出现的那一个)。这样操作直到完全匹配好。详见代码:
#pragma comment(linker, "/STACK:10240000,10240000") #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set>
#include <bitset>
#include <functional>
#include <numeric>
#include <stdexcept>
#include <utility> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define rep_up0(a, b) for (int a = 0; a < (b); a++)
#define rep_up1(a, b) for (int a = 1; a <= (b); a++)
#define rep_down0(a, b) for (int a = b - 1; a >= 0; a--)
#define rep_down1(a, b) for (int a = b; a > 0; a--)
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
#define pchr(a) putchar(a)
#define pstr(a) printf("%s", a)
#define sstr(a) scanf("%s", a);
#define sint(a) ReadInt(a)
#define sint2(a, b) ReadInt(a);ReadInt(b)
#define sint3(a, b, c) ReadInt(a);ReadInt(b);ReadInt(c)
#define pint(a) WriteInt(a)
#define if_else(a, b, c) if (a) { b; } else { c; }
#define if_than(a, b) if (a) { b; }
#define test_print1(a) cout << "var1 = " << a << endl
#define test_print2(a, b) cout << "var1 = " << a << ", var2 = " << b << endl
#define test_print3(a, b, c) cout << "var1 = " << a << ", var2 = b" << ", var3 = " << c << endl typedef double db;
typedef long long LL;
typedef pair<int, int> pii;
typedef multiset<int> msi;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int, int> mii; const int dx[] = {, , -, };
const int dy[] = {-, , , };
const int maxn = 1e2 + ;
const int maxm = 1e3 + ;
const int maxv = 1e7 + ;
const int max_val = 1e6 + ;
const int MD = ;
const int INF = 1e9 + ;
const double pi = acos(-1.0);
const double eps = 1e-; template<class T>T gcd(T a, T b){return b==?a:gcd(b,a%b);}
template<class T>void ReadInt(T &x){char c=getchar();while(!isdigit(c))c=getchar();x=;while(isdigit(c)){x=x*+c-'';c=getchar();}}
template<class T>void WriteInt(T i) {int p=;static int b[];if(i == ) b[p++] = ;else while(i){b[p++]=i%;i/=;}for(int j=p-;j>=;j--)pchr(''+b[j]);}
template<class T>bool max_update(T &a,const T &b){if(b>a){a = b; return true;}return false;}
template<class T>bool min_update(T &a,const T &b){if(b<a){a = b; return true;}return false;}
template<class T>T condition(bool f, T a, T b){return f?a:b;}
template<class T>void copy_arr(T a[], T b[], int n){rep_up0(i,n)a[i]=b[i];}
int make_id(int x, int y, int n) { return x * n + y; } int n, m;
int a[maxn][maxn], b[maxn][maxn], buf[maxn][maxn]; int swap_col(int y1, int y2) {
rep_up0(i, n) {
swap(a[i][y1], a[i][y2]);
}
} int equal_col(int y1, int y2) {
rep_up0(i, n) {
if (a[i][y1] != b[i][y2]) return false;
}
return true;
} int copy_rec() {
rep_up0(i, n) {
rep_up0(j, m) {
a[i][j] = buf[i][j];
}
}
}
int copy_rec2() {
rep_up0(i, n) {
rep_up0(j, m) {
buf[i][j] = a[i][j];
}
}
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
while (cin >> n >> m, n >= || m >= ) {
rep_up0(i, n) {
rep_up0(j, m) {
sint(a[i][j]);
}
}
rep_up0(i, n) {
rep_up0(j, m) {
sint(b[i][j]);
}
}
int ok = ;
copy_rec2();
rep_up0(i, m) {
copy_rec();
swap_col(, i);
copy_rec2();
int flag[];
rep_up0(j, n) {
flag[j] = a[j][] != b[j][];
}
rep_up0(j, n) {
for (int k = ; k < m; k++) {
a[j][k] ^= flag[j];
}
}
int yes = ;
for (int j = ; j < m; j++) {
int ok0 = ;
for (int k = j; k < m; k++) {
if (equal_col(k, j)) {
swap_col(k, j);
ok0 = ;
break;
}
}
if (!ok0) {
yes = ;
break;
}
}
if (yes) {
ok = ;
break;
}
}
puts(ok? "Yes" : "No");
}
return ;
}
[hdu3484]枚举的更多相关文章
- Swift enum(枚举)使用范例
//: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...
- 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)
建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...
- Objective-C枚举的几种定义方式与使用
假设我们需要表示网络连接状态,可以用下列枚举表示: enum CSConnectionState { CSConnectionStateDisconnected, CSConnectionStateC ...
- Help Hanzo (素数筛+区间枚举)
Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000). (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...
- 枚举:enum
枚举 所谓枚举就是指定好取值范围,所有内容只能从指定范围取得. 例如,想定义一个color类,他只能有RED,GREEN,BLUE三种植. 使用简单类完成颜色固定取值问题. 1,就是说,一个类只能完成 ...
- .NET 基础一步步一幕幕[方法、结构、枚举]
方法.结构.枚举 方法: 将一堆代码进行重用的一种机制. 语法: [访问修饰符] 返回类型 <方法名>(参数列表){ 方法主体: } 返回值类型:如果不需要写返回值,写void 方法名:P ...
- Asp.Net 将枚举类型(enum)绑定到ListControl(DropDownList)控件
在开发过程中一些状态的表示使用到枚举类型,那么如何将枚举类型直接绑定到ListControl(DropDownList)是本次的主题,废话不多说了,直接代码: 首先看工具类代码: /// <su ...
- 用枚举enum替代int常量
枚举的好处: 1. 类型安全性 2.使用方便性 public class EnumDemo { enum Color{ RED(3),BLUE(5),BLACK(8),YELLOW(13),GREEN ...
- c#编程基础之枚举
枚举的意义就在于限制变量取值范围. 当可以确定的几种取值时才可以用. 如果输入一个字符串需要进行判断是否是我们需要的字符串时,则一般需要这样写: using System; using System. ...
随机推荐
- Windows环境下搭建Cocos2d-x3.2环境并配置android交叉编译环境
一.软件 1)VS2012(C++11特性在VS2012以上可以使用):传送门: 2)Cocos2d-x官网源码:传送门:http://cocos2d-x.org/download 3)JDK:传送门 ...
- 详解 方法的覆盖 —— toString() 与 equals()的覆盖
在学习本篇博文前,建议先学习完本人的博文--<详解 继承(上)-- 工具的抽象与分层> 在本人之前的博文中曾讲过"基类"的知识,那么,本篇博文中的主题--Object类 ...
- 5. class--extends
ES5: function article(x,y){ this.x = x; this.y = y; } article.prototype.say = function() { return (t ...
- [转]PHP利用PCRE回溯次数限制绕过某些安全限制
这次Code-Breaking Puzzles中我出了一道看似很简单的题目pcrewaf,将其代码简化如下: <?php function is_php($data){ return preg_ ...
- 深度剖析前端JavaScript中的原型(JS的对象原型)
这张图片有点劝退了,哈哈哈~ 通过原型机制,JavaScript 中的对象从其他对象继承功能特性:这种继承机制与经典的面向对象编程语言的继承机制不同.本文将探讨这些差别,解释原型链如 ...
- 十分钟搞懂Elasticsearch数字搜索原理
更多精彩内容请看我的个人博客或者扫描二维码,关注微信公众号:佛西先森 前言 Elasticsearch诞生的本意是为了解决文本搜索太慢的问题,ES会默认将所有的输入内容当作字符串来理解,对于字段类型是 ...
- GoJS 教程新手入门(资源整理,解决方案)
以下几个是我在百度.谷歌 上能找到的比较全的GoJs的一些东西,希望对各位有所帮助! 如有外网网站不能访问请自行FQ GoJS官网 第一个推荐的是GoJS的一个类似于社区的问题讨论区,这里面初学者的一 ...
- Java ASM学习(2)
1.编译后的方法区,其中存储的代码都是一些字节码指令 2.Java虚拟机执行模型: java代码是在一个线程内部执行,每个线程都有自己的执行栈,栈由帧组成,每个帧表示一个方法的调用,每调用一个方法,都 ...
- Deepin15.11-mysql5.7安装与配置
目录 1.卸载 2.换源 3.安装mysql-5.7并修改密码 4.修改mysql中字符编码 deepin系统中,默认的系统源,使用apt-get install mysql-server会自动拉取m ...
- Windows 挂起进程
A thread can suspend and resume the execution of another thread. While a thread is suspended, it is ...