链接:https://ac.nowcoder.com/acm/contest/558/C来源:牛客网 小猫在研究二元组. 小猫在研究最大值. 给定N个二元组(a1,b1),(a2,b2),…,(aN,bN),请你从中选出恰好K个,使得ai的最小值与bi的最小值之和最大. 请输出ai的最小值与bi的最小值之和 输入描述: 第一行两个正整数N,K,表示二元组数量与需要选的数量. 接下来N行,第i行两个正整数ai,bi. 输出描述: 一行一个正整数,表示最大的a_i的最小值与b_i的最小值之和. 示例…
链接:https://ac.nowcoder.com/acm/contest/558/G 来源:牛客网 路径 小猫在研究树. 小猫在研究路径. 给定一棵N个点的树,每条边有边权,请你求出最长的一条路径,满足经过每个点最多一次,经过的边的条数为偶数,且边权和最大. 请输出这个最大的边权和. 输入描述: 第一行一个正整数N,表示节点个数. 接下来N−1行,第i行三个正整数 ui,vi,wi,表示第i条边连接点ui,vi,边权为wi. 输出描述: 一行一个正整数,表示最大的边权和. 示例1 输入 复制…
链接:https://ac.nowcoder.com/acm/contest/558/D来源:牛客网 寻找 小猫在研究树. 小猫在研究树上的距离. 给定一棵N个点的树,每条边边权为1. Q次询问,每次给定a,b,c,请你输出a到b的路径上离c最近的点的编号. 输入描述: 第一行一个正整数N,表示节点数量. 接下来N−1行,第i行两个正整数ui,vi,表示第i条边连接节点ui,vi. 接下来一行一个正整数Q,表示询问数量. 接下来Q行,每行三个正整数a,b,c,表示一组询问. 输出描述: Q行,每…
链接:https://ac.nowcoder.com/acm/contest/558/A来源:牛客网 A.串串 小猫在研究字符串. 小猫在研究字串. 给定一个长度为N的字符串S,问所有它的子串Sl…r(1≤l≤r≤N),去重后有多少种. 输入描述: 一行一个字符串S. 输出描述: 一行一个整数,表示答案. 示例1 输入 复制 ababa 输出 复制 9 备注: 1≤N≤10 5 ,字符都是小写字母 后缀自动机模板题,因为数据太大,极限可能为1e10,要开long long 不会后缀自动机,贴个板…
链接:https://ac.nowcoder.com/acm/contest/558/G来源:牛客网 小猫在研究树. 小猫在研究路径. 给定一棵N个点的树,每条边有边权,请你求出最长的一条路径,满足经过每个点最多一次,经过的边的条数为偶数,且边权和最大. 请输出这个最大的边权和. 输入描述: 第一行一个正整数N,表示节点个数. 接下来N−1行,第i行三个正整数 ui,vi,wi,表示第i条边连接点ui,vi,边权为wi. 输出描述: 一行一个正整数,表示最大的边权和. 输入 5 1 2 5 1…
链接:https://ac.nowcoder.com/acm/contest/558/H 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 小猫在研究字符串. 小猫在研究奇数的性质. 给定一个字符串S,请你输出将其奇数位的字符提出来以后得到的字符串.   输入描述: 第一行一个正整数T,表示数据组数.接下来T行,每行一个字符串S,表示每组数据. 输出描述: T行,每行一个字符…
链接:https://ac.nowcoder.com/acm/contest/558/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 小猫在研究序列. 小猫在研究单调性. 给定一个长度为N的序列a1,a2,…,aN,请你选出一个最长的区间[l,r](1≤l≤r≤N),满足al≤al+1≤…≤ar. 如果有多个,请输出l最小的. 输入描述: 第一行一个正整数T,表示数据组…
题目链接:https://ac.nowcoder.com/acm/contest/558/B import java.util.HashSet; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner reader=new Scanner(System.in); HashSet set=new HashSet(); int N=reader.nextInt(); i…
题目链接:https://ac.nowcoder.com/acm/contest/558/D 就是求有多少块区域,用DFS就可以解决,一遇到一个1就从其开始深搜,将其所在的区域块覆灭(变为0),再遇到一个1,重复此操作. Accept import java.util.Scanner; public class Main { static int old=0; static int N; static int M; static char array[][]; static int x[]={-…
https://www.nowcoder.com/acm/contest/124#question 题意  找第一个不小于K的数的下标,然后对它前一个数加一 解析   我们可以维护一个最大值数组  1到 i的 最大值 就是max[ i ]  二分找到最左边的值 但是 找到的前一个加1 要用线段树来维护最大值 但是 这么写会超时... 超时代码 #include <bits/stdc++.h> using namespace std; typedef long long ll; ,maxn=1e…
我觉得我可以继续wa下去(手动魔鬼笑)--------------------------------------------   原题链接:https://ac.nowcoder.com/acm/contest/12986/J 示例1 输入 5 1 5 2 3 4 1 输出 0 0 0 0 0 示例2 输入 6 1 1 1 4 5 1 4 输出 0 0 3 4 0 3 题意给定n个数, 每次操作使所有正整数-1, 直到没有任何一个数==k思路我们的目的是把所有>=k的数操作完后!=k, 那..…
链接:https://www.nowcoder.com/acm/contest/131/B来源:牛客网 矩阵 M 包含 R 行 C 列,第 i 行第 j 列的值为 Mi,j. 请寻找一个子矩阵,使得这个子矩阵的和最大,且满足以下三个条件: 子矩阵的行数不能超过 X 行. 子矩阵的列数不能超过 Y 列. 子矩阵中 0 的个数不能超过 Z 个. 请输出满足以上条件的最大子矩阵和. 输入描述: 第一行输入五个整数 R,C,X,Y,Z. 接下来 N 行,每行输入 M 个整数,第 i 行第 j 列的整数表…
链接: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…
链接:牛客网暑期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) 的两条不相交(可重合)路径,因为起点重合了,所以把其中一条路径往左上平移了…
链接: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…
链接:https://www.nowcoder.com/acm/contest/147/D来源:牛客网 Niuniu likes traveling. Now he will travel on a special graph. Given k and n, The directed graph contains n vertices, which are numbered from 0 to n - 1. For the vertex i, and for 1 <= j <= k, ther…
https://www.nowcoder.com/acm/contest/144/G 链接:https://www.nowcoder.com/acm/contest/144/G来源:牛客网 In Viridian forest there is a tree T formed by N nodes, each edge on which has a positive weight. There is an undirected graph G generated from tree T, whi…
链接:https://www.nowcoder.com/acm/contest/140/B来源:牛客网 题目描述 White Rabbit wants to buy some drinks from White Cloud. There are n kinds of drinks, and the price of i-th drink is p[i] yuan per bottle. Since White Cloud is a good friend of White Rabbit, whe…
链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所有的x,y∈V均有xy∈E等价于m(x)m(y)∈E1,则称G和G1是同构的,这样的一个映射m称之为一个同构,如果G=G1,则称他为一个自同构. 题目描述 Two undirected simple graphs and where are isomorphic when there exists…
链接:https://www.nowcoder.com/acm/contest/142/G来源:牛客网 The mode of an integer sequence is the value that appears most often. Chiaki has n integers a1,a2,...,an. She woud like to delete exactly m of them such that: the rest integers have only one mode an…
链接:https://www.nowcoder.com/acm/contest/141/J来源:牛客网 Eddy has graduated from college. Currently, he is finding his future job and a place to live. Since Eddy is currently living in Tien-long country, he wants to choose a place inside Tien-long country…
链接:https://www.nowcoder.com/acm/contest/141/A来源:牛客网 Eddy was a contestant participating in ACM ICPC contests. ACM is short for Algorithm, Coding, Math. Since in the ACM contest, the most important knowledge is about algorithm, followed by coding(impl…
链接: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 following…
链接: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 randomness in…
链接:https://www.nowcoder.com/acm/contest/140/I来源:牛客网 White Cloud has a square of n*n from (1,1) to (n,n). White Rabbit wants to put in several cars. Each car will start moving at the same time and move from one side of one row or one line to the other…
链接:https://www.nowcoder.com/acm/contest/140/D来源:牛客网 White Cloud has built n stores numbered from 1 to n. White Rabbit wants to visit these stores in the order from 1 to n. The store numbered i has a price a[i] representing that White Rabbit can spend…