
二分
文章平均质量分 55
旺 崽
这个作者很懒,什么都没留下…
展开
-
LeetCode 5790 查询差绝对值的最小值
题目链接一个数组 a 的 差绝对值的最小值 定义为:0 <= i < j < a.length 且 a[i] != a[j] 的 |a[i] - a[j]| 的 最小值。如果 a 中所有元素都 相同 ,那么差绝对值的最小值为 -1 。比方说,数组 [5,2,3,7,2] 差绝对值的最小值是 |2 - 3| = 1 。注意答案不为 0 ,因为 a[i] 和 a[j] 必须不相等。给你一个整数数组 nums 和查询数组 queries ,其中 queries[i] = [li, ri]原创 2021-06-20 19:50:17 · 18072 阅读 · 0 评论 -
AtCoder Beginner Contest 203(Sponsored by Panasonic)D.Pond
题目链接Problem StatementThe land of a park AtCoder is an N×NN×NN×N grid with east-west rows and north-south columns. The height of the square at the i-th row from the north and j-th column from the west is given as Ai,jA_{i,j}Ai,j.Takahashi, the manager,原创 2021-06-01 19:43:00 · 6612 阅读 · 0 评论 -
ZONe Energy Programming Contest C.MAD TEAM
题目链接思维+二分如果暴力选三个,复杂度为 C30003C_{3000}^3C30003,显然不可取,可以二分答案 ansansans,这样可以把每个属性值更新成 000 或 111 (判断 ansansans 和属性值大小)而言,这样五个属性值的情况最多为 25=322^5=3225=32,再从中暴力选即可,AC代码如下:#include <bits/stdc++.h>using namespace std;typedef long long ll;int n, flag原创 2021-05-09 16:25:59 · 18108 阅读 · 4 评论 -
2020牛客寒假算法基础集训营5 B.牛牛战队的比赛地
2020牛客寒假算法基础集训营5 B.牛牛战队的比赛地题目描述由于牛牛战队经常要外出比赛,因此在全国各地建立了很多训练基地,每一个基地都有一个坐标(x,y)。这周末,牛牛队又要出去比赛了,各个比赛的赛点都在xx轴上。牛牛战队为了方便比赛,想找一个到达训练基地最大距离最小的地方作为比赛地。这个问题对于牛牛战队太简单了,它就交给了你,你来帮他算一下~输入描述:输入数据第一行包含一个整数N(...原创 2020-02-14 11:46:35 · 4170 阅读 · 2 评论 -
LeetCode 74 搜索二维矩阵
题目链接编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性:每行中的整数从左到右按升序排列。每行的第一个整数大于前一行的最后一个整数。示例 1:输入:matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3输出:true示例 2:输入:matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13输出:false看到有序原创 2021-03-30 20:21:41 · 1812 阅读 · 0 评论 -
2021年广东工业大学第十五届文远知行杯程序设计竞赛(同步赛)E.捡贝壳
题目链接题目描述小明来到一片海滩上,他很喜欢捡贝壳,但他只喜欢质量为x的倍数的贝壳。贝壳被排列成一条直线,下标从 111 到 nnn 编号,小明打算从编号为区间 [l,r]\left [l,r \right ][l,r] 的贝壳中,捡起所有他喜欢的贝壳。你能帮他计算出他能捡多少贝壳吗。给出一个大小为 n(n≤105)n(n\le10^5)n(n≤105) 的数组,下标从 111 到 nnn 编号,a1,a2,...an(ai≤105)a_1,a_2,...a_n (a_i \le 10^5)a1原创 2021-03-29 22:12:27 · 2102 阅读 · 0 评论 -
LeetCode 1802 有界数组中指定下标处的最大值
题目链接给你三个正整数 n、index 和 maxSum 。你需要构造一个同时满足下述所有条件的数组 nums(下标 从 0 开始 计数):nums.length == nnums[i] 是 正整数 ,其中 0 <= i < nabs(nums[i] - nums[i+1]) <= 1 ,其中 0 <= i < n-1nums 中所有元素之和不超过 maxSumnums[index] 的值被最大化返回你所构造的数组中的 nums[index] 。注意:abs原创 2021-03-22 20:20:29 · 2576 阅读 · 0 评论 -
LeetCode 5691 通过最少操作次数使数组的和相等
LeetCode 5691 通过最少操作次数使数组的和相等题目链接给你两个长度可能不等的整数数组 nums1 和 nums2 。两个数组中的所有值都在 1 到 6 之间(包含 1 和 6)。每次操作中,你可以选择 任意 数组中的任意一个整数,将它变成 1 到 6 之间 任意 的值(包含 1 和 6)。请你返回使 nums1 中所有数的和与 nums2 中所有数的和相等的最少操作次数。如果无法使两个数组的和相等,请返回 -1 。示例 1:输入:nums1 = [1,2,3,4,5,6], nums原创 2021-02-28 20:00:44 · 1884 阅读 · 0 评论 -
AtCoder Beginner Contest 192 D.Base n
AtCoder Beginner Contest 192 D.Base nProblem StatementGiven are a string X consisting of 0 through 9, and an integer M.Let d be the greatest digit in X.How many different integers not greater than M can be obtained by choosing an integer n not less tha原创 2021-02-24 09:50:40 · 1794 阅读 · 0 评论 -
LeetCode 1208 尽可能使字符串相等
LeetCode 1208 尽可能使字符串相等题目链接给你两个长度相同的字符串,s 和 t。将 s 中的第 i 个字符变到 t 中的第 i 个字符需要 |s[i] - t[i]| 的开销(开销可能为 0),也就是两个字符的 ASCII 码值的差的绝对值。用于变更字符串的最大预算是 maxCost。在转化字符串时,总开销应当小于等于该预算,这也意味着字符串的转化可能是不完全的。如果你可以将 s 的子字符串转化为它在 t 中对应的子字符串,则返回可以转化的最大长度。如果 s 中没有子字符串原创 2021-02-21 11:18:02 · 1740 阅读 · 0 评论 -
LeetCode 778 水位上升的泳池中游泳
LeetCode 778 水位上升的泳池中游泳题目链接在一个 N x N 的坐标方格 grid 中,每一个方格的值 grid[i][j] 表示在位置 (i,j) 的平台高度。现在开始下雨了。当时间为 t 时,此时雨水导致水池中任意位置的水位为 t 。你可以从一个平台游向四周相邻的任意一个平台,但是前提是此时水位必须同时淹没这两个平台。假定你可以瞬间移动无限距离,也就是默认在方格内部游动是不耗时的。当然,在你游泳的时候你必须待在坐标方格里面。你从坐标方格的左上平台 (0,0) 出发。最少耗时多久你才能原创 2021-02-16 10:35:21 · 1710 阅读 · 0 评论 -
LeetCode 1631 最小体力消耗路径
LeetCode 1631 最小体力消耗路径题目链接你准备参加一场远足活动。给你一个二维 rows x columns 的地图 heights ,其中 heights[row][col] 表示格子 (row, col) 的高度。一开始你在最左上角的格子 (0, 0) ,且你希望去最右下角的格子 (rows-1, columns-1) (注意下标从 0 开始编号)。你每次可以往 上,下,左,右 四个方向之一移动,你想要找到耗费 体力 最小的一条路径。一条路径耗费的 体力值 是路径上相邻格子之间 高度差绝原创 2021-02-15 09:45:57 · 2013 阅读 · 0 评论 -
LeetCode 1712 将数组分成三个子数组的方案数
LeetCode 1712 将数组分成三个子数组的方案数题目链接我们称一个分割整数数组的方案是 好的 ,当它满足:数组被分成三个 非空 连续子数组,从左至右分别命名为 left , mid , right 。left 中元素和小于等于 mid 中元素和,mid 中元素和小于等于 right 中元素和。给你一个 非负 整数数组 nums ,请你返回 好的 分割 nums 方案数目。由于答案可能会很大,请你将结果对 109 + 7 取余后返回。示例 1:输入:nums = [1,1,1]输出:1原创 2021-01-04 10:56:59 · 30662 阅读 · 1 评论 -
第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(上海)D.Walker
第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(上海)D.Walker原创 2020-12-19 16:29:06 · 4097 阅读 · 2 评论 -
Technocup 2020 - Elimination Round 1 C. Save the Nature
Technocup 2020 - Elimination Round 1 C. Save the Nature题目链接You are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something!You have n tickets to sell. The price of the i-th tick原创 2020-12-17 20:59:57 · 2376 阅读 · 0 评论 -
Codeforces 1250J The Parade
Codeforces 1250J The ParadeThe Berland Army is preparing for a large military parade. It is already decided that the soldiers participating in it will be divided into k rows, and all rows will contain the same number of soldiers.Of course, not every arra原创 2020-12-17 18:41:47 · 2333 阅读 · 0 评论 -
LeetCode 34 在排序数组中查找元素的第一个和最后一个位置
LeetCode 34 在排序数组中查找元素的第一个和最后一个位置题目链接给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。如果数组中不存在目标值 target,返回 [-1, -1]。进阶:你可以设计并实现时间复杂度为 O(log n) 的算法解决此问题吗?示例 1:输入:nums = [5,7,7,8,8,10], target = 8输出:[3,4]示例 2:输入:nums = [5,7,7,8,8,10], tar原创 2020-12-01 19:07:36 · 2338 阅读 · 0 评论 -
Codeforces Round #671 (Div. 2) D2. Sage‘s Birthday (hard version)
Codeforces Round #671 (Div. 2) D2. Sage’s Birthday (hard version)题目链接Today is Sage’s birthday, and she will go shopping to buy ice spheres. All n ice spheres are placed in a row and they are numbered from 1 to n from left to right. Each ice sphere has a原创 2020-10-09 16:27:58 · 2319 阅读 · 0 评论 -
POJ 3579 Median
POJ 3579 Median题目链接DescriptionGiven N numbers, X1, X2, … , XN, let us calculate the difference of every pair of numbers: ∣Xi - Xj∣ (1 ≤ i < j ≤ N). We can get C(N,2) differences through this work, and now your task is to find the median of the differenc原创 2020-10-07 15:16:36 · 3288 阅读 · 0 评论 -
牛客练习赛70 B.拼凑
牛客练习赛70 B.拼凑题目链接题目描述牛牛还是很喜欢字符串"puleyaknoi"。牛牛有T个超长超长的字符串,不过这次他更懒了,他希望直接在字符串中看见他喜欢的字符串。如果一个子串中含有一个子序列是”puleyaknoi“,那么他就把这个子串称作好的子串。牛牛是个懒人,他不喜欢看太长的子串,那样他会觉着眼镜很累。你能帮他求出对于每个字符串,最短的好的子串的长度是多少吗?如果没有,请输出-1。输入描述:第一行一个T表示数据组数接下来T行每行一个字符串(保证字符串只含小写字母)输出描原创 2020-09-26 09:28:30 · 2554 阅读 · 0 评论 -
POJ 3104 Drying
POJ 3104 Drying题目链接DescriptionIt is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She is not afraid of this boring process. Jane has decided to use a radiator to make drying faster. But the radiator is small,原创 2020-09-25 16:56:08 · 2401 阅读 · 0 评论 -
POJ 3685 Matrix
POJ 3685 Matrix题目链接DescriptionGiven a N × N matrix A, whose element in the i-th row and j-th column Aij is an number that equals i2+100000×i+j2−100000×j+i×ji^2 + 100000 × i + j^2 - 100000 × j + i × ji2+100000×i+j2−100000×j+i×j, you are to find the M-th原创 2020-09-25 10:52:31 · 2355 阅读 · 0 评论 -
Codeforces Round #200 (Div. 1) C. Read Time
Codeforces Round #200 (Div. 1) C. Read Time题目链接Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel.When viewed from the side, Mike’s hard drive is an endless原创 2020-09-24 18:10:49 · 2465 阅读 · 0 评论 -
Codeforces Round #218 (Div. 2) C. Hamburgers
Codeforces Round #218 (Div. 2) C. Hamburgers题目链接Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausa原创 2020-09-23 19:33:00 · 2527 阅读 · 0 评论 -
LeetCode 538 把二叉搜索树转换为累加树
LeetCode 538 把二叉搜索树转换为累加树题目链接给定一个二叉搜索树(Binary Search Tree),把它转换成为累加树(Greater Tree),使得每个节点的值是原来的节点值加上所有大于它的节点值之和。例如:输入: 原始二叉搜索树: 5 / \ 2 13输出: 转换为累加树: 18 / \ 20 13将每个点的权值存入一个数组然后排序,计算前缀和,然后再对每个点二分比它大的点的位置,更新结点即可,AC代码原创 2020-09-21 18:51:28 · 2370 阅读 · 0 评论 -
牛客小白月赛27 H.社团游戏
牛客小白月赛27 H.社团游戏题目链接题目描述在民风淳朴的雏见泽,号称能“完美犯罪”的天才牛牛,又开始和社团的萌妹子牛妹玩起了游戏。在今天的游戏中,牛牛将会得到一个 n×mn\times mn×m 且全为小写字母的矩阵,他可以从矩阵中任选一块正方形,但必须保证该正方形中任意一类小写字母个数之和不能超过 kkk,换而言之,在该正方形中,‘a’字符个数不能超过 kkk,‘b’字符个数不能超过 kkk,…,‘z’字符个数不能超过 kkk。现在牛牛想知道,以 (i,j)(i,j)(i,j) 为左上角且符合原创 2020-08-24 10:19:24 · 2443 阅读 · 0 评论 -
牛客编程巅峰赛S1第11场 - 黄金&钻石 C.牛牛找子集
牛客编程巅峰赛S1第11场 - 黄金&钻石 C.牛牛找子集题目链接题目描述牛牛和牛妹在玩一个游戏,在他们面前有n个数。牛妹说出一个数字k,牛牛就要从这些数中找到多个由k个数字组成的子集,每个数字有且只能使用一次,并且这些子集是完全相同的,子集内部元素可以相同,完全相同的子集是指两个集合里的元素及其个数都是相同的。游戏胜利的目标是:找到满足游戏规则,且数量最多的子集。牛牛特别想赢得游戏,所以他想请你帮他写一个程序,找到能够满足游戏胜利条件的子集,并且输出这个子集。如果有多个子集满足条件,输出原创 2020-08-14 10:54:50 · 2554 阅读 · 0 评论 -
牛客 24086 Haybale Feast
牛客 24086 Haybale Feast题目链接题目描述Farmer John is preparing a delicious meal for his cows! In his barn, he has N haybales (1≤N≤100,000)(1≤N≤100,000)(1≤N≤100,000). The iith haybale has a certain flavor Fi(1≤Fi≤109)F_i (1≤F_i≤10^9 )Fi(1≤Fi≤109) and a certai原创 2020-08-09 11:17:52 · 2476 阅读 · 0 评论 -
AtCoder Beginner Contest 174 E.Logs
AtCoder Beginner Contest 174 E.Logs题目链接到最后才发现是二分,菜菜的我/(ㄒoㄒ)/~~我们直接二分 [1,max{a[i]}][1,max\lbrace a[i]\rbrace][1,max{a[i]}] 即可,对每一个 midmidmid,每个数 a[i]a[i]a[i] 只需要切 a[i]−1mid\frac{a[i]-1}{mid}mida[i]−1 刀即可(可以自己弄几个例子证明一下),判断每一个 midmidmid 需要的总刀数和 kkk 的关系即可原创 2020-08-03 08:49:45 · 2537 阅读 · 0 评论 -
AtCoder Beginner Contest 143 D.Triangles
AtCoder Beginner Contest 143 D.Triangles题目链接暴力肯定不行的,我们可以先枚举两条边,然后通过公式二分找第三条边的数量即可,AC代码如下:#include<bits/stdc++.h>using namespace std;typedef long long ll;int main(){ int n,ans=0; cin>>n; vector<int>a(n); for(int i=0;i<原创 2020-08-02 11:20:35 · 2430 阅读 · 0 评论 -
AtCoder Beginner Contest 172 C.Tsundoku
AtCoder Beginner Contest 172 C.Tsundoku题目链接又被 C 坑了,我一直以为的 DFS 或者 DP,后来发现二分就可以了,因为每次都只能从头取,那么我们只需预处理出前缀,对每个 aaa 的前缀 aia_iai,从 bbb 的前缀中二分出大于 k−aik-a_ik−ai 的下标,每次更新一下答案即可,AC代码如下:#include<bits/stdc++.h>using namespace std;typedef long long ll;in原创 2020-06-28 09:12:46 · 2560 阅读 · 0 评论 -
哈尔滨理工大学软件与微电子学院程序设计竞赛(同步赛)B.Min Value
哈尔滨理工大学软件与微电子学院程序设计竞赛(同步赛)B.Min Value题目链接题目描述有一天,老师告诉多多:绝对值是指一个数在数轴上所对应点到原点的距离。接下来老师给多多一个由 N 个数组成的序列 a1,a2,a3,······,an-1,an,他想让多多从中任选两个数 ai 和 aj,使得 ai + aj 的绝对值最小,并且计算出 i + j 的值,其中 i ≠ j。由于老师给出的序列太长,多多无法完成这个任务,请你帮助他。输入描述:输入第一行包含一个正整数 N (2 ≤ N ≤ 100原创 2020-06-15 09:27:58 · 2414 阅读 · 0 评论 -
Codeforces Round #645 (Div. 2) D. The Best Vacation
Codeforces Round #645 (Div. 2) D. The Best Vacation题目链接You’ve been in love with Coronavirus-chan for a long time, but you didn’t know where she lived until now. And just now you found out that she lives in a faraway place called Naha.You immediately dec原创 2020-06-10 09:16:19 · 2348 阅读 · 0 评论 -
牛客小白月赛25 G.解方程
牛客小白月赛25 解方程题目链接题目描述牛能作为一个学霸,非常擅长解方程。有一天,他拿到了一个方程:xa+blnx=cx^a+blnx=cxa+blnx=c牛能当然一下子就解出了这个方程。但他想考考聪明的你,这个方程的解的多少?输入描述:三个正整数 a,b,c输出描述:如果解存在,请输出方程的解x的值,若你和正确答案的误差不超过 10−710^{-7}10−7 ,则认为你的答案正确。如果解不存在,则输出。示例1输入3 5 1输出1.00000000000000很容易观原创 2020-05-20 10:04:15 · 2606 阅读 · 0 评论 -
Educational Codeforces Round 87 (Rated for Div. 2) D.Multiset
Educational Codeforces Round 87 (Rated for Div. 2) D.Multiset题目链接Note that the memory limit is unusual.You are given a multiset consisting of n integers. You have to process queries of two types:add integer k into the multiset;find the k-th order sta原创 2020-05-18 21:10:41 · 2493 阅读 · 0 评论 -
Codeforces Round #642 (Div. 3) D.Constructing the Array
Codeforces Round #642 (Div. 3) D.Constructing the Array题目链接You are given an array a of length n consisting of zeros. You perform n actions with this array: during the i-th action, the following sequence of operations appears:Choose the maximum by length原创 2020-05-15 19:33:08 · 2378 阅读 · 0 评论 -
牛客练习赛63 C.牛牛的揠苗助长
牛客练习赛63 C.牛牛的揠苗助长题目链接题目描述牛牛有一块长度大小为n的菜园,他首先对这块菜园从1到n进行了编号,每一块地分别为1号、2号…n号菜地,然后他往每块菜地中都种下了一些水稻,一开始,第i块菜地中的水稻高度均为a[i]个单位。然后我们知道水稻的生长周期都是n天,也就是说每逢n天水稻就会长高一个单位。但是不巧的是整个菜园中每一块菜地的生长周期都错开了,具体来说,第1天的时候第1块菜地中的水稻长高一个单位,第2天的时候第2块菜地中的水稻长高一个单位…第n天的时候第n块菜地中的水稻长高一个单位,原创 2020-05-09 08:29:49 · 2370 阅读 · 0 评论 -
POJ 3189 Steady Cow Assignment
POJ 3189 Steady Cow Assignment题目链接DescriptionFarmer John’s N (1 <= N <= 1000) cows each reside in one of B (1 <= B <= 20) barns which, of course, have limited capacity. Some cows really...原创 2020-04-21 16:15:36 · 2295 阅读 · 0 评论 -
POJ 2112 Optimal Milking
POJ 2112 Optimal Milking题目链接DescriptionFJ has moved his K (1 <= K <= 30) milking machines out into the cow pastures among the C (1 <= C <= 200) cows. A set of paths of various lengths r...原创 2020-04-21 15:32:33 · 2329 阅读 · 0 评论 -
POJ 2289 Jamie's Contact Groups
POJ 2289 Jamie’s Contact Groups题目链接DescriptionJamie is a very popular girl and has quite a lot of friends, so she always keeps a very long contact list in her cell phone. The contact list has becom...原创 2020-04-21 10:02:42 · 2569 阅读 · 0 评论