描述太困难,简单说下最后的版本,选任意一个2x2矩阵,让其中4个数异或之后相等。
思路:The Very Beautiful Blanket 题解 - 洛谷专栏 写的太好 ,没得说,可以直接看对方的
感觉大家都最好点一下,省的显得我喧宾夺主
1.很明显随着下标的移动,迟早会要求所有2x2矩阵的异或值相同
2.这个题解,首先知道相同值异或后为0(a^a=0),最精妙的点就是发现2x2矩阵中,同一行的行标相等,同一列的列标相等,对列标进行位移,使值区分开来,接下来就变成相同异或相同,跟离散化差不多(其实感觉就是离散化),然后跟离散化一样的,值肯定使不同的,但是由于位操作
i<<9的部分会成0,j的部分也会成0,<<9其实意义就是为了成功离散开来,没其他意义。
代码: 几乎是抄的,太短了,写的太过精妙没得说
cpp
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define int128 __int128
#define endl '\n'
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+10;
const int INF = 1e18;
const int MOD = 2023;
void solve(){
int n,m;
cin >> n >> m;
cout << n*m << endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cout << ((i<<9)^j) << " ";
}
cout << endl;
}
}
signed main(){
IOS;
int t=1;
cin >> t;
while(t--){
solve();
}
}