正文
增加 10 行删除 10 行
80 行未改动818283848586878889909192939495969798991001011021031041051061071083 行未改动1121131141151161171181191201211221231241251261271281291301311321331341351361377 行未改动80 行未改动using namespace std;const int N = 60;int n;int h[N]; // h[i] 表示第 i 个柱子的高度int a[N][N]; // a[i][j] 表示第 i 个柱子,从下往上数第 j 个球的大小bool check(int x, int y) // 判断 x+y 是否为完全平方数{int k = 1;while (k * k <= x + y){if (k * k == x + y) return true;k ++ ;}return false;}signed main(){cin >> n;int tot = 0, now = 1; // tot 表示已经开了的柱子数量,now 表示目前应该放的球的大小(注意,并非已经放的最大球的大小!P2765 魔术球问题)for (int i = 1; i <= n; i ++ ) // 递推计算 n=i 时的答案{while (true){bool flag = true;3 行未改动h[j] ++ , a[j][h[j]] = now ++ ;flag = false;break;}if (flag == true) // 无法放入,则新开一个柱子,若亦无法新开柱子,则已得到 n=i 的一个结果{if (tot < i) tot ++ , h[tot] = 1, a[tot][1] = now, now ++ ;else break;}}}int sum = 0;for (int i = 1; i <= n; i ++ ) sum += h[i];cout << sum << "\n";for (int i = 1; i <= n; i ++ ){for (int j = 1; j <= h[i]; j ++ ) cout << a[i][j] << " ";cout << "\n";}return 0;}```7 行未改动80 行未改动818283848586878889909192939495969798991001011021031041051061071083 行未改动1121131141151161171181191201211221231241251261271281291301311321331341351361377 行未改动80 行未改动using namespace std;const int N = 60;int n;int h[N]; // h[i] 表示第 i 个柱子的高度int a[N][N]; // a[i][j] 表示第 i 个柱子,从下往上数第 j 个球的大小bool check(int x, int y) // 判断 x+y 是否为完全平方数{int k = 1;while (k * k <= x + y){if (k * k == x + y) return true;k ++ ;}return false;}signed main(){cin >> n;int tot = 0, now = 1; // tot 表示已经开了的柱子数量,now 表示目前应该放的球的大小(注意,并非已经放的最大球的大小!P2765 魔术球问题)for (int i = 1; i <= n; i ++ ) // 递推计算 n=i 时的答案{while (true){bool flag = true;3 行未改动h[j] ++ , a[j][h[j]] = now ++ ;flag = false;break;}if (flag == true) // 无法放入,则新开一个柱子,若亦无法新开柱子,则已得到 n=i 的一个结果{if (tot < i) tot ++ , h[tot] = 1, a[tot][1] = now, now ++ ;else break;}}}int sum = 0;for (int i = 1; i <= n; i ++ ) sum += h[i];cout << sum << "\n";for (int i = 1; i <= n; i ++ ){for (int j = 1; j <= h[i]; j ++ ) cout << a[i][j] << " ";cout << "\n";}return 0;}```7 行未改动