Omkar and Duck
Mier_Samuelle · · 题解
可以发现,一条从左上角到右下角的路径,一定经过了每条副对角线恰好一次。一个自然的想法是,将每条副对角线视作一个数位,给该条对角线上的每个格子赋上不同的权值,直接把路径上经过的所有格子的权值拼成一个整数。
然而这样肯定塞不进
以样例为例,对于
对于第一组询问,给定
:::success[Code]{open}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[30][30];
signed main(){
int n, q;
cin >> n;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (i & 1){
a[i][j] = 0;
}
else{
a[i][j] = 1ll << (i + j);
}
cout << a[i][j] << " ";
}
cout << endl;
}
cin >> q;
while (q--){
ll k;
cin >> k;
int x = 0, y = 0;
for (int i = 1; i < 2 * n; i++){
cout << x + 1 << " " << y + 1 << endl;
if (k >> i & 1){
if (x & 1){
x++;
}
else{
y++;
}
}
else{
if (x & 1){
y++;
}
else{
x++;
}
}
}
}
return 0;
}
:::