建议添加 hack 数据
查看原帖
建议添加 hack 数据
31756
RiverHamster楼主2022/5/6 10:29

如果采用原地求逆,需要复杂的交换行/列操作,而原数据主元不在对角线上的 case 很少。

可以用以下生成器生成一个稀疏斜对称矩阵,求逆后对角线都是 00

#include <cstdio>
#include <random>
using namespace std;

int a[405][405];
const int M = 1000000007;

mt19937 rng(0);
uniform_int_distribution<int> D(1, M - 1);

int main() {
  freopen("input.txt", "w", stdout);
  int n = 400;
  printf("%d\n", n);
  uniform_int_distribution<int> P(0, n - 1);
  for (int i = 0; i < n; ++i) {
    for (int t = 0; t < 3; ++t) {
      int j = P(rng);
      if (j == i) continue;
      a[i][j] = D(rng); a[j][i] = M - a[i][j];
    }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      printf("%d%c", a[i][j], " \n"[j == n - 1]);
}

可以用 这篇题解 中的代码生成答案。

2022/5/6 10:29
加载中...