题意:给两个个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]枚举的更多相关文章

  1. Swift enum(枚举)使用范例

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  2. 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)

    建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...

  3. Objective-C枚举的几种定义方式与使用

    假设我们需要表示网络连接状态,可以用下列枚举表示: enum CSConnectionState { CSConnectionStateDisconnected, CSConnectionStateC ...

  4. Help Hanzo (素数筛+区间枚举)

    Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000).     (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...

  5. 枚举:enum

    枚举 所谓枚举就是指定好取值范围,所有内容只能从指定范围取得. 例如,想定义一个color类,他只能有RED,GREEN,BLUE三种植. 使用简单类完成颜色固定取值问题. 1,就是说,一个类只能完成 ...

  6. .NET 基础一步步一幕幕[方法、结构、枚举]

    方法.结构.枚举 方法: 将一堆代码进行重用的一种机制. 语法: [访问修饰符] 返回类型 <方法名>(参数列表){ 方法主体: } 返回值类型:如果不需要写返回值,写void 方法名:P ...

  7. Asp.Net 将枚举类型(enum)绑定到ListControl(DropDownList)控件

    在开发过程中一些状态的表示使用到枚举类型,那么如何将枚举类型直接绑定到ListControl(DropDownList)是本次的主题,废话不多说了,直接代码: 首先看工具类代码: /// <su ...

  8. 用枚举enum替代int常量

    枚举的好处: 1. 类型安全性 2.使用方便性 public class EnumDemo { enum Color{ RED(3),BLUE(5),BLACK(8),YELLOW(13),GREEN ...

  9. c#编程基础之枚举

    枚举的意义就在于限制变量取值范围. 当可以确定的几种取值时才可以用. 如果输入一个字符串需要进行判断是否是我们需要的字符串时,则一般需要这样写: using System; using System. ...

随机推荐

  1. 判断一个字符串是否是合法IP地址

    # -*- coding: utf-8 -*- """ @File:test06_判断ip地址是否合法.py @E-mail:364942727@qq.com @Time ...

  2. 数据挖掘入门系列教程(十)之k-means算法

    简介 这一次我们来讲一下比较轻松简单的数据挖掘的算法--K-Means算法.K-Means算法是一种无监督的聚类算法.什么叫无监督呢?就是对于训练集的数据,在训练的过程中,并没有告诉训练算法某一个数据 ...

  3. VideoView--简单的设置全屏幕播放

    我说的最主要的是要在布局哪里设置一下,如: <com.example.mypalyer.fullScreen          android:id="@+id/videoView1& ...

  4. discuz-目录

    由于工作原因,开始学习discuz,0基础开发,学了一会总结了一些

  5. 关于搭建IIS网页弹出登录框的解决方案

    今天自己搭建IIS服务器的时候,明明设置了匿名访问,但是用ie访问127.0.0.1的时候还是会弹出一个登陆框,最后在网上找到答案. 转自: https://blog.csdn.net/sunleib ...

  6. Docker简单操作(二)

    1.docker容器简单操作 docker search 镜像名 #搜索镜像.如docker search nginx docker pull alpine #拉取镜像.alpine是比较小的镜像 d ...

  7. CTO为何要微服务评估

    为什么定义参考模型 之前我的工作,大部分时间都是聚焦在某个产品/团队,为他们提供微服务/DevOps的实施及指导.进入公司后,同时参与了多个产品团队的改造研讨.其中最大的不同在于: 在面对一个团队的时 ...

  8. (原創) 如何在Nios II顯示8位數的七段顯示器? (SOC) (Nios II) (SOPC Builder) (DE2-70)

    Abstract本文討論如何在Nios II控制8位數的七段顯示器. Introduction使用環境:Quartus II 8.0 + Nios II EDS 8.0 + DE2-70 (Cyclo ...

  9. 提高Web服务器并发响应的经历

    1 前言 ---------- 最近一直在维护一个线上运行的旧系统,系统本身的问题很多,然而又有大量客户准备试用.之前一直存有侥幸心理,希望系统能神奇的顶过这段时间,但这个蜗牛般的系统残忍的告诉我们- ...

  10. 设置 Linux 支持中文

    1.首先在 command 输入 locale,可以看到 Linux 下默认的系统语言的是英文 2.vim ~/.bashrc 打开这个文件,该文件夹相当于系统配置文件 3.打开后,将后三行命令输入到 ...