首页 > 其他分享 >牛客小白月赛 64 C题

牛客小白月赛 64 C题

时间:2023-01-04 00:55:12浏览次数:35  
标签:int res 牛客 vector 64 数组 小白月赛 row

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

相关文章

  • leetcode-645. 错误的集合
    645.错误的集合-力扣(Leetcode)又用了哈希表,又用了数学计算,看题解有个位运算看不太懂funcfindErrorNums(nums[]int)[]int{m:=make(map[int]struct{},len(nu......
  • leetcode-643. 子数组最大平均数 I
    643.子数组最大平均数I-力扣(Leetcode)滑动窗口,判断好边界条件即可funcfindMaxAverage(nums[]int,kint)float64{begin,end:=0,k-1ifend>=len(n......
  • 牛客进阶题目3:不重叠序列检测
    还是移位寄存器,加一个计数器来限制周期题目要求状态机,懒得画了,移位寄存器可根据时序图直接写`timescale1ns/1nsmodulesequence_detect( inputclk, inputrst_n, i......
  • NC25064 [USACO 2007 Mar G]Ranking the Cows
    题目链接题目题目描述EachofFarmerJohn'sNcows(1≤N≤1,000)producesmilkatadifferentpositiverate,andFJwouldliketoorderhiscowsaccording......
  • 牛客进阶题目2:含有无关项的序列检测
    跟上一题类似这里有人可能会用到casex,最好别用,有的工具可能不支持`timescale1ns/1nsmodulesequence_detect( inputclk, inputrst_n, inputa, outputregmatch......
  • 牛客进阶题目1:输入序列连续检测
    检测01110001序列,满足序列则拉高match可以用状态机和移位寄存器,懒得画状态转移图,直接用移位寄存器解注意题中match在检测到序列后的下一周期拉高,所以需要延一拍`timesca......
  • acwing4644. 求和
    题目原题链接参考题解方法1思路求两两相乘的和,求a[i]与每个a[j]的乘积的和,就是求a[j]的和与a[i]的乘积所有先把所有数求和sum,然后让\(a[i]*(sum-a[i])\),枚举每一个......
  • 新建 Microsoft Office Word 文档 来源:牛客网
    题目链接:https://ac.nowcoder.com/acm/contest/28886/1015时间限制:C/C++1秒,其他语言2秒空间限制:C/C++32768K,其他语言65536K64bitIOFormat:%lld题目描述CSL正在学习......
  • 经商 来源:牛客网
    题目链接:https://ac.nowcoder.com/acm/contest/28886/1022时间限制:C/C++1秒,其他语言2秒空间限制:C/C++32768K,其他语言65536K64bitIOFormat:%lld题目描述小d是一个搞......
  • 4644. 求和
    4644.求和给定n个整数a1,a2,⋅⋅⋅,an,求它们两两相乘再相加的和,即S=a1⋅a2+a1⋅a3+⋅⋅⋅+a1⋅an+a2⋅a3+⋅⋅⋅+an−2⋅an−1+an−2⋅an+an−1⋅an输入格式输入......