洛谷 P5441 【XR-2】伤痕
思路
奇怪的构造思路……
讲不懂,看原题解吧,洛谷题解
顺便 % 一波 xht。
代码
/*
Name: P5441 【XR-2】伤痕
Author: Loceaner
Date: 08/09/20 17:40
Description:
Debug:
*/
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int A = 1e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
inline int read() {
char c = getchar();
int x = 0, f = 1;
for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return x * f;
}
int n, a[A];
int main() {
n = read();
if (n == 1) return cout << "0\n0\n", 0;
cout << n * (n - 3) * (n * n + 6 * n - 31) / 48 << '\n';
int m = (n + 1) >> 1;
for (int i = 1; i <= n; i++) {
memset(a, 0, sizeof(a));
for (int j = 1; j <= m; j++) a[(i + j - 1) % n + 1] = 1;
for (int j = 1; j <= n; j++) cout << a[j] << " ";
puts("");
}
return 0;
}
转载不必联系作者,但请声明出处