异或矩阵(构造)

// Problem: 异或矩阵
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/11197/B
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 2022-02-18 20:10:00
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;

#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define pii pair<int, int>
#define mset(s,t) memset(s,t,sizeof(t))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define fir first
#define pb push_back
#define sec second
#define sortall(x) sort((x).begin(),(x).end())

inline int read () {
	int x = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) f |= (ch=='-'),ch= getchar();
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return f?-x:x;
}
template<typename T> void print(T x) {
	if (x < 0) putchar('-'), x = -x;
	if (x >= 10) print(x/10);
	putchar(x % 10 + '0');
}
ll n, m;
string get (int x) {
    string s = "";
    while (x) {
        if (x & 1) s += "1";
        else s += "0";
        x >>= 1;
    }
    reverse(s.begin(), s.end());
    return s;
}
void solve() {
    cin >> n >> m;
    ll temp = n * m;
    ll cnt = 0;
    while (temp) {
        temp >>= 1;
        cnt ++;
    }
    ll ans = pow(2, cnt) - 1;
    cout << ans << endl;
    if (ans == n * m) {
        cout << n << " " << m << " " << n << " " << m << endl;
    }
    else {
        ll a = ans / 2, b = ans / 2 + 1;
        ll x1 = (a - 1) / m + 1, y1 = (a - 1) %m + 1;
        ll x2 = (b - 1) / m + 1, y2 = (b - 1) % m + 1;
        if (x1 == x2) {
            cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
        }
        else {
            cout << x1 << " " << 1 << " " << x2 << " " << m << endl;
        }
    }
}
int main () {
    int t;
    t =1;
    while (t --) solve();
    return 0;
}



通过打表发现最大值是pow(2, cnt[n*m] ) - 1; 如何构造出这样的矩阵 在构造的时候我一直在构造一种包含超过2个的矩阵。这样的矩阵是很难找的。 实际上我们能通过两个值来异或成一个值 如果x1,x2不同的时候,我们会发现为整个矩阵。复制一份在右边。加偏移量

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值