异或矩阵(构造)

网友投稿 665 2022-12-01

异或矩阵(构造)

异或矩阵(构造)

// Problem: 异或矩阵// Contest: NowCoder// URL: Memory Limit: 524288 MB// Time Limit: 2000 ms// 2022-02-18 20:10:00// // Powered by CP Editor (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#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 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不同的时候,我们会发现为整个矩阵。复制一份在右边。加偏移量

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:商城小程序怎么开发(小程序商城怎么开发自己的小程序)
下一篇:小程序商城怎么开发(微信小程序商城开发流程)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~