洛谷 P5441 【XR-2】傷痕
阿新 • • 發佈:2020-09-08
思路
奇怪的構造思路……
講不懂,看原題解吧,洛谷題解
順便 % 一波 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; }