https://ac.nowcoder.com/acm/contest/50044/C
1 #include<bits/stdc++.h> 2 using namespace std; 3 //贪心构造 我认为思路是其一 , 然后模拟这个过程还是比较重要的 4 const int N = 100100; 5 6 int n, k, idx = 1; 7 8 int main() { 9 cin >> n >> k; 10 vector<vector<int>> res(k + 1, vector<int> (n + 1));//直接开二维数组会爆栈 , 所以用stl开一个动态的 11 // vector<vector<int>> res(row, vector<int> (col, 0)); 12 // 定义一个row * col 且初始值为0的动态数组 13 14 for (int i = 1; i <= n; i ++ ) { 15 for (int j = 1; j <= k; j ++ ) { 16 res[j][i] += i / k; 17 } 18 for (int j = 1; j <= i % k; j ++ ) { 19 res[idx ++ ][i] += 1; 20 if (idx == k + 1) idx = 1; 21 } 22 } 23 24 for (int i = 1; i <= k; i ++ ) 25 for (int j = 1; j <= n; j ++ ) 26 printf("%d%c", res[i][j], j == n ? '\n' : ' ');//好东西, 以后输出空格就这么写了 27 28 return 0; 29 } 30 /* 31 cin: 32 5 5 33 cout: 34 0 0 1 1 1 35 0 0 1 1 1 36 1 0 1 0 1 37 0 1 0 1 1 38 0 1 0 1 1 39 */
vector 开动态二维数组的语法请自行百度
标签:int,res,牛客,vector,64,数组,小白月赛,row From: https://www.cnblogs.com/llihaotian666/p/17023803.html