链接: https://www.nowcoder.com/acm/contest/141/C 题意: 给出一个n个元素的序列(1,2,...,n)和m个操作(1≤n,m≤1e5),每个操作给出两个数p和s(1≤pi≤n,1≤si≤n-pi+1),表示把序列中从p开始的s个数移到最前面,例如序列[1,2,3,4,5]在p=2,s=3时变成序列[2,3,4,1,5],输出最后的序列. 分析: 对于每个操作,直接把序列拆成三个部分,再重新拼接一下就行.可以用Splay或rope来快速完成这个操作. 代…
链接: https://www.nowcoder.com/acm/contest/141/A 题意: 有n(1≤n≤36)个物品,每个物品有四种代价pi,ai,ci,mi,价值为gi(0≤pi,ai,ci,mi,gi≤36),求四种代价分别不超过P,A,C,M(0≤P,A,C,M≤36)的条件下能获得的最大价值,输出所选择的物品. 分析: 01背包的思路,只是代价多了几个而已,数组开多几维就好了.可以用vis[i][p][a][c][m]来表示在四种代价分别为p,a,c,m的状态下是否用第i件物…
(牛客场场有笛卡尔树,场场都不会用笛卡尔树...自闭,补题心得) 题目链接:https://ac.nowcoder.com/acm/contest/884/C 题意:给出两个序列a,b,求max{min a[l,r]*sum b[l,r]} 一个比较显然的做法是通过线段树/ST表维护区间最值,不过nlogn的做法容易被卡常,(zkw线段树可过)不过赛时提高了时限到3s,基本上就很好写了 直接维护区间最小/大值下标,然后从最小值开始进行计算答案,在最小值的左边找到最小/最大的前缀和(找最大是为了处…
#include <bits/stdc++.h> using namespace std; vector<int> path; ; short dp[maxn][maxn][maxn][maxn][maxn]; bool tp[maxn][maxn][maxn][maxn][maxn]; int P,C,A,M; int p[maxn],c[maxn],a[maxn],m[maxn],g[maxn]; int main() { int n; scanf("%d"…
题目链接:https://ac.nowcoder.com/acm/contest/888/A 题意:求出有多少个不被包含的全1子矩阵 解题思路:首先对列做处理,维护每个位置向上1的个数,然后我们从最后一行开始处理(方便去重),通过单调栈维护每个点左右第一个小于它的值的下标l[j],r[j],那么(l[j]-1,r[j]-1)就是以当前行为矩阵底的左右边界(左右无法再扩展,向上也不能),我们只需维护当前左右边界相同的矩阵,上一次所覆盖到的矩阵上边界,如果这个矩阵底所在行小于前一个相同左右边界矩阵的…
链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, find out the K-th minimum weighted clique. A subset of vertices of an undirected graph is called clique if and only if every two distinct vertices in th…
链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Niuniu likes to play OSU! We simplify the game OSU to the following problem. Given n and m, there are n clicks. Each c…
链接:https://www.nowcoder.com/acm/contest/145/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K Special Judge, 64bit IO Format: %lld 题目描述 You have a n * m grid of characters, where each character is an English letter (lowercase or uppercase, w…
链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言524288K Special Judge, 64bit IO Format: %lld 题目描述 A binary string s of length N = 2n is given. You will perform the following operation n times : - Choos…
链接:https://www.nowcoder.com/acm/contest/145/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K Special Judge, 64bit IO Format: %lld 题目描述 You have a complete bipartite graph where each part contains exactly n nodes, numbered from 0 to n - 1…
链接: https://www.nowcoder.com/acm/contest/139/I 题意: 给出一个n(1≤n≤5e4)个字符的字符串s(si ∈ {a,b,c}),求最多可以从n*(n+1)/2个子串中选出多少个子串,使得它们互不同构.同构是指存在一个映射f,使得字符串a的每个字符都可以映射成字符串b的对应字符.例如ab与ac.ba.bc.ca.cb都是同构的. 分析: 以字符串abba为例:现在只考虑这个字符串的2个子串ab和ba,如果不考虑重构,有2个子串,否则,只有1个子串.这…
链接: https://www.nowcoder.com/acm/contest/139/J 题意: 给出n个整数的序列a(1≤ai≤n)和q个询问(1≤n,q≤1e5),每个询问包含两个整数L和R(1≤L,R≤n).对于每个询问,输出a[1...L]和a[R...n]的不同数字的个数. 分析: 将原数组复制一份拼接到末尾,把询问a[1...L]和a[R...n]转换为询问a[R...L+n].设kind[i]为a[1...i]出现的数字种类,则询问a[L...R]的答案为 kind[R] -…
链接: https://www.nowcoder.com/acm/contest/139/F 题意: 分析: 转载自:http://tokitsukaze.live/2018/07/19/2018niuke1.F/ 代码: #include <cstdio> #include <cassert> #include <algorithm> using namespace std; /// 注意mod,使用前须调用一次 polysum::init(int M); names…
链接: https://www.nowcoder.com/acm/contest/139/E 题意: 给出一个n(1≤n≤1e5)个整数(范围是1至10)的序列,求从中移除m(1≤m≤min(n-1,10))个整数后不同序列的数量模(1e9+7). 分析: 设d[i][t]表示当前匹配到了第i个数字,总共删了t个数字时的不同序列的数量.先不考虑序列重复的情况,则d[i][t] = d[i-1][t](不删第i个数字)+ d[i-1][t-1](删第i个数字).现在考虑减去重复的序列.设有序列ab…
链接: https://www.nowcoder.com/acm/contest/139/D 题意: 两个无向简单图都有n(1≤n≤8)个顶点,图G1有m1条边,图G2有m2条边,问G2有多少个子图与G1同构. 分析: 枚举所有的映射方案,再判断合法性,把每一合法映射所用到的边状态压缩一下,装到集合里去重即可. 代码: import java.io.*; import java.util.*; public class Main { Scanner cin = new Scanner(new B…
链接: https://www.nowcoder.com/acm/contest/139/B 题意: 求满足以下条件的n*n矩阵A的数量模m:A(i,j) ∈ {0,1,2}, 1≤i,j≤n.A(i,j) = A(j,i), 1≤i,j≤n.A(i,1) + A(i,2) + ... + A(i,n) = 2, 1≤i≤n.A(1,1) = A(2,2) = ... = A(n,n) = 0.其中1≤n≤1e5, 1≤m≤1e9. 分析: 把矩阵看成无向图的邻接矩阵,即要求所有点度为2,即每个…
链接: https://www.nowcoder.com/acm/contest/139/A 题意: 求满足以下条件的n*m矩阵A的数量模(1e9+7):A(i,j) ∈ {0,1,2}, 1≤i≤n, 1≤j≤m.A(i,j) ≤ A(i+1,j), 1≤i<n, 1≤j≤m.A(i,j) ≤ A(i,j+1), 1≤i≤n, 1≤j<m.其中1 ≤ n,m ≤ 1e3. 分析: 考虑01和12的分界线,是(n,0)到(0,m)的两条不相交(可重合)路径.平移其中一条变成(n+1,1)到(1…
题目链接:https://ac.nowcoder.com/acm/contest/889/H 题意:给出n颗竹子的高度,q次询问,每次询问给出l,r,x,y,每次选取[l,r]中的竹子,砍y次砍掉所有竹子,每次砍下来的竹子长度和是相同的,问你第x次应该砍在哪个高度上 解题思路:由于总共砍的次数已经给出,因此我们可以知道砍x次总共砍的量 Total = $\sum\limits_{i=l}^{r}$h[i]*x/y,那么问题就变成了一个方程$\sum\limits_{i=l}^{r}$max(0,…
题意:给你一个N×N的矩阵,求最大的子矩阵 满足子矩阵中最大值和最小值之差小于等于m. 思路:这题是求满足条件的最大子矩阵,毫无疑问要遍历所有矩阵,并判断矩阵是某满足这个条件,那么我们大致只要解决两个问题就能搞定这题 (1)如何遍历所有矩阵 (2)如何判断此矩阵满足条件 我们先来看(2) 题目中说的是我们只要让这个矩阵中的最大值和最小值之差小于等于m就满足条件,那么问题就转化为如何快速求得二维矩阵的最值 这个时候就需要用到单调队列了,…
题目链接:https://ac.nowcoder.com/acm/contest/883/F 题意:给定n×n的矩阵,求最大子矩阵使得子矩阵中最大值和最小值的差值<=M. 思路:先看数据大小,注意题目说所有样例的N^3不超过25e7,意思就是我们可以用O(n^3)过题. 最大子矩阵第二场出现过,做法是枚举上下边界实现降维,同时我们维护每一列的最大值最小值,然后枚举右边界,这时候复杂度已经为O(n^3).那么左边界怎么确定呢?我们用两个单调队列维护子矩阵的最大值最小值,根据题目条件确定左边界,注意…
题意:给你一个n*n的高度矩阵 要你找到里面最大的矩阵且最大的高度差不能超过m 思路:我们首先枚举上下右边界,然后我们可以用单调队列维护一个最左的边界 然后计算最大值 时间复杂度为O(n*n*n) #include<bits/stdc++.h> #define ll long long const int inf = 0x3f3f3f3f; const int N = 507; const ll mod = 998244353; using namespace std; int a[N][N]…
链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there are always lots of randomness in the game. For most of the cards game, the very first step in the game is shuffling the cards. And, mostly the randomn…
链接:https://www.nowcoder.com/acm/contest/141/E 来源:牛客网 题目描述 Eddy likes to play with string which is a sequence of characters. One day, Eddy has played with a string S for a long time and wonders how could make it more enjoyable. Eddy comes up with foll…
链接:https://www.nowcoder.com/acm/contest/105/H来源:牛客网 n个桶按顺序排列,我们用1~n给桶标号.有两种操作: 1 l r c 区间[l,r]中的每个桶中都放入一个颜色为c的球 (1≤l,r ≤n,l≤r,0≤c≤60) 2 l r   查询区间[l,r]的桶中有多少种不同颜色的球     (1≤l,r ≤n,l≤r) 输入描述: 有多组数据,对于每组数据:第一行有两个整数n,m(1≤n,m≤100000)接下来m行,代表m个操作,格式如题目所示.…
链接:https://www.nowcoder.com/acm/contest/147/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Niuniu has recently learned how to use Gaussian elimination to solve systems of linear equations. Given n and a[i], wh…
链接:https://ac.nowcoder.com/acm/contest/884/I来源:牛客网 题目描述 We call a,ba,ba,b non-equivalent if and only if a≠ba \neq ba​=b and a≠rev(b)a \neq rev(b)a​=rev(b), where rev(s)rev(s)rev(s) refers to the string obtained by reversing characters of sss, for e…
链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 题目描述 Two arrays u and v each with m distinct elements are called equivalent if and only if RMQ(u,l,r)=RMQ(v,l,r)RMQ(u,l,r)=RMQ(v,l,r) for all 1≤l≤r≤m1≤l≤r≤mwhere RMQ(w,l,r)RMQ(w,l,r) denotes the inde…
链接:https://ac.nowcoder.com/acm/contest/881/B 来源:牛客网 Integration 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048576K 64bit IO Format: %lld 题目描述 Bobo knows that ∫ ∞ 0 1 1 x 2 d x = π 2 . ∫0∞11+x2 dx=π2. Given n distinct positive integers a 1 , a 2 , -…
链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048576K 64bit IO Format: %lld 题目描述 Two arrays u and v each with m distinct elements are called equivalent if and only if R M Q ( u ,…
链接:https://ac.nowcoder.com/acm/contest/882/F来源:牛客网 Given 2N people, you need to assign each of them into either red team or white team such that each team consists of exactly N people and the total competitive value is maximized. Total competitive va…