leetcode contest weekly 351

【前缀和】LeetCode 523. 连续的子数组和

题目链接 523. 连续的子数组和 思路 参考宫水三叶大佬题解 一开始以为和 Leetcode 53 Maximum Subarray 思路差不多,都是求子数组的值。但是后来发现在53题中并没有求出每个子数组的和,只是在贪心的情况下求出了可能的最大和 代码 class Solution { publ ......
前缀 数组 LeetCode 523

AtCoder Regular Contest 104 F Visibility Sequence

洛谷传送门 AtCoder 传送门 考虑连边 $(i,p_i)$(若 $p_i = -1$ 则不连边),可以发现形成了一篇内向树森林且这个森林存在一个 dfs 序为 $1,2,...,n$。 这棵森林有如下性质: $\forall v \in son_u,h_u > h_v$ $\forall v, ......
Visibility Sequence AtCoder Regular Contest

[LeetCode] 1042. Flower Planting With No Adjacent

You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. I ......
LeetCode Adjacent Planting Flower 1042

AtCoder Beginner Contest 298

A - Job Interview (abc298 a) 题目大意 给定包含o-x的字符串,问是否不包含 x且包含o。 解题思路 遍历一遍即可。 神奇的代码 ```cpp #include using namespace std; using LL = long long; int main(voi ......
Beginner AtCoder Contest 298

AtCoder Beginner Contest 223(D,E,F)

AtCoder Beginner Contest 223(D,E,F) D(拓扑排序) D 大意就是有$n$个点,$m$个关系,其中关系是指$u$和$v$,在排序里面使得$u$的位置再$v$的位置的前面 要求找到一个排序满足上述条件的序列中字典序最小的那一个 这个使用拓扑排序,并加上优先队列即可 只 ......
Beginner AtCoder Contest 223

AtCoder Beginner Contest 293 补题记录 (E-G)

E 题意:给定 A, X, M, 计算 (A0 + A1 + A2 + ... + AX-1) mod M (1 <= A, M <= 109, 1 <= X <= 1012)。 根据等比数列求和公式,(A0 + A1 + A2 + ... + AX-1) mod M = ((AX - 1) / ( ......
Beginner AtCoder Contest 293 E-G

2022 Shanghai Collegiate Programming Contest B

知识点:差分约束 Link:https://codeforces.com/gym/103931/problem/B。 被卡 SPFA 了呃呃。 一看出题人是这个人: 如何看待 SPFA 算法已死这种说法? - fstqwq 的回答 - 知乎,那没事了。 简述 给定参数 $n, q$,表示有一个长度为 ......
Programming Collegiate Shanghai Contest 2022

LeetCode 115. 不同的子序列

class Solution { public: long long f[1010][1010];//f[i][j]表示s前i个字符得到t前j个字符的所有方案 int numDistinct(string s, string t) { f[0][0]=1; int n=s.size(),m=t.si ......
序列 LeetCode 115

AtCoder Regular Contest 104 D Multiset Mean

洛谷传送门 AtCoder 传送门 很平凡的一道计数啊。 考虑将所有数都减去 $x$,那么就要求选的数和为 $0$。 正负分开考虑,$0$ 可以任意选。需要多重背包求 $f_{i,j}$ 表示选 $1 \sim i$ 的数和为 $j$ 的方案数。前缀和优化是平凡的。 code // Problem: ......
Multiset AtCoder Regular Contest Mean

LeetCode/最大化城市的最小供电站数目

政府批准了可以额外建造 k 座供电站,你需要决定这些供电站分别应该建在哪里,这些供电站与已经存在的供电站有相同的供电范围。 给你两个整数 r 和 k ,如果以最优策略建造额外的发电站,返回所有城市中,最小供电站数目的最大值是多少。 ###一. 二分法+前缀和+贪心 分析:最大化最小值,首先考虑使用二 ......
供电站 数目 LeetCode 城市

leetcode-1337-easy

The K Weakest Rows in a Matrix You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers ......
leetcode 1337 easy

leetcode-1342-easy

Number of Steps to Reduce a Number to Zero Given an integer num, return the number of steps to reduce it to zero. In one step, if the current number i ......
leetcode 1342 easy

leetcode-1360-easy

Number of Days Between Two Dates Write a program to count the number of days between two dates. The two dates are given as strings, their format is YY ......
leetcode 1360 easy

leetcode-766-easy

Toeplitz Matrix Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false. A matrix is Toeplitz if every diagonal from top ......
leetcode easy 766

leetcode-806-easy

Number of Lines To Write String You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase ......
leetcode easy 806

leetcode-812-easy

Largest Triangle Area Given an array of points on the X-Y plane points where points[i] = [xi, yi], return the area of the largest triangle that can be ......
leetcode easy 812

leetcode-830-easy

Positions of Large Groups In a string s of lowercase letters, these letters form consecutive groups of the same character. For example, a string like ......
leetcode easy 830

leetcode-844-easy

Backspace String Compare Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace c ......
leetcode easy 844

leetcode-944-easy

Delete Columns To Make Sorted You are given an array of n strings strs, all of the same length. The strings can be arranged such that there is one on ......
leetcode easy 944

代码随想录算法训练营Day01 | LeetCode704 二分查找、Leetcode27 移除元素

今日学习的视频和文章 代码随想录数组基础 复习基础知识 代码随想录 二分查找 代码随想录 移除元素 LeetCode704 二分查找 题目链接:704. 二分查找 - 力扣(Leetcode) 以前学二分查找的时候,真的一直搞不清楚怎么操作左边界和有边界,以及循环的终止条件是什么,总是自己慢慢调试出 ......
随想录 训练营 随想 算法 LeetCode

leetcode_打卡04

leetcode_打卡04 题目:605. 种花问题 解答: 三种情况: 第一个1的左边全是0的情况,此时 可以插入的位置为result=(i-1+1)/2 ,如【0,0,0,1,0,0,1】 两个1之间全是0的情况。此时 可以插入的位置为result=(i-flag-1-2+1)/2 第一个1的右 ......
leetcode

LeetCode 周赛 340,质数 / 前缀和 / 极大化最小值 / 最短路 / 平衡二叉树

本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 提问。 大家好,我是小彭。 上周跟大家讲到小彭文章风格的问题,和一些朋友聊过以后,至少在算法题解方面确定了小彭的风格。虽然竞赛算法题的文章受众非常小,但却有很多像我一样的初学者,他们有兴趣参加但容易被题目难度和大神选 ......
质数 前缀 LeetCode 340

AtCoder Regular Contest 110 E Shorten ABC

洛谷传送门 AtCoder 传送门 考虑把 $\text{A}$ 看成 $1$,$\text{B}$ 看成 $2$,$\text{C}$ 看成 $3$,那么一次操作相当于选择一个 $a_i \ne a_{i+1}$ 的 $i$,将 $a_i$ 和 $a_{i+1}$ 替换成一个数 $a_i \opl ......
AtCoder Regular Contest Shorten 110

LeetCode习题——有效的完全平方数(二分查找)

有效的完全平方数 力扣链接:367. 有效的完全平方数 题目 给你一个正整数 num 。如果 num 是一个完全平方数,则返回 true ,否则返回 false 。 完全平方数是一个可以写成某个整数的平方的整数。换句话说,它可以写成某个整数和自身的乘积。 不能使用任何内置的库函数,如 sqrt 。 ......
习题 LeetCode

2012-2013 ACM-ICPC, NEERC, Moscow Subregional Contest题解

题目链接:2012-2013 ACM-ICPC, NEERC, Moscow Subregional Contest C. Cinderella(贪心) 思路 答案为大于平均值的数的数量 代码 #include <bits/stdc++.h> using namespace std; using i ......
题解 Subregional ACM-ICPC Contest Moscow

[LeetCode] 1440. Jump Game V 跳跃游戏之五

Given an array of integers arr and an integer d. In one step you can jump from index i to index: i + x where: i + x < arr.length and 0 < x <= d. i - x ......
LeetCode 1440 Jump Game

【前缀和】LeetCode 1031. 两个非重叠子数组的最大和

题目链接 1031. 两个非重叠子数组的最大和 思路 代码 class Solution { public int maxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen) { // 求一个前缀和 for(int i = 1; i < n ......
前缀 数组 LeetCode 两个 1031

【前缀和】LeetCode 1423. 可获得的最大点数

题目链接 1423. 可获得的最大点数 思路 通过逆向思维来考虑,因为我们是从两头拿数字,所以最终剩下的数字一定是位于中间的连续子数组。 因为数组总和不变,所以求两边数字加和的最大值,实际上就是求中间数字加和的最小值 代码 class Solution { public int maxScore(i ......
前缀 点数 LeetCode 1423

【DP】【分治】LeetCode 53. 最大子数组和

题目链接 [https://leetcode.cn/problems/maximum-subarray/description/](53. 最大子数组和 "https://leetcode.cn/problems/maximum-subarray/description/") 思路 分析动态规划题目 ......
数组 LeetCode 53

剑指 Offer 09. 用两个栈实现队列 && leetcode225.用队列实现栈

剑指 Offer 09. 用两个栈实现队列 class CQueue { private: stack<int> inStack, outStack; void in2out(){ //这里必须是while循环,如果是if判断,则输出栈日常只有一个值,没有起到先入后出的作用 while(!inSta ......
队列 amp leetcode 两个 Offer