HPrefix Sum study from : https://blog.csdn.net/mitsuha_/article/details/81774727 k较小.分离x和k. 另外的可能:求a[k][x],x不确定,想到的是求sum(a[k][1]+a[k][2]+...+a[k][x]),树状数组 sum(x)-sum(x-1).这题用不上. #include <cstdio> #include <cstdlib> #include <cmath> #incl…
链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之后第一个数字消失.求最后为空串需要多少秒. 题解: (1)如果在消除一个 0 前经过了 n 秒,那么消掉这个 0 需要 n + 1 秒. (2)如果在消除一个 1 前经过了 n 秒,那么消掉这个 1 与其产生的所有数需要 (n + 1) * 2 秒. (3)如果在消除一个 2 前经过了 n 秒,那么…
链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n打开盒子.当她打开一个盒子时,如果里面有一颗钻石并且比它的钻石大,那么她将用她的钻石代替它. 现在您需要计算预期的替换次数. 您只需要输出答案模块998244353. 注意:如果x%998244353 = y * d%998244353,那么我们表示x / y%998244353 = d%99824…
牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人感觉是带约束条件的超级楼梯问题.说是dp其实就是递推吧.只要连续的两秒不是跑的就可以.所以在已经跑了i步的时候,直接考虑最后一步是跑的还是走的就可以了. 所以公式就是dp[i]=dp[i-1]+dp[i-1-k];然后前缀和预处理一下,直接从L的for到R的就可以了. 反正乱七八糟就出来了.现在写题…
牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你一共有几种填法. 变形一下就会发现其实是走非交叉格子路径计数,限制条件下的非降路径问题.就是从左上到右下走格子路径.从上到下为0——n,从左到右为0——m. 考虑 01 和 12 的分界线,是 (n, 0) 到 (0, m) 的两条不相交(可重合)路径,因为起点重合了,所以把其中一条路径往左上平移了…
牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献) 链接:https://ac.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calculating the number of coprime pairs within some range. This problem can be solved with inclusion-exclusion meth…
2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld 题目描述 White Cloud has a square of n*n from (1,1) to (n,n). White Rabbit wants to know the maximum…
链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 题目描述 A binary string s of length N = 2n is given. You will perform the following operation n times : - Choose one of the operators AND (&), OR (|) or XOR (^). Suppose the current and s2i. For examp…
链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048576K 64bit IO Format: %lld 题目描述 Given a sequence of integers a1, a2, ..., an and q pairs of integers (l1, r1), (l2, r2), ..., (lq, rq), find count(l1,…
链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian elimination to solve systems of linear equations. Given n and a[i], where n is a power of 2, let's consider an n x n matrix A. The index of A[i][j] an…