当前位置:网站首页>LeetCode周赛 + AcWing周赛(T4/T3)分析对比
LeetCode周赛 + AcWing周赛(T4/T3)分析对比
2022-07-05 00:57:00 【OpenAll_Zzz】
前言
两道题之间的共同点在于子数组价值的定义,LC为子数组的和乘上其长度,AcWing为子数组的和除上其长度(平均值)。
分析 - AcWing T3
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1000010;
int n;
LL s[N];
int stk[N];
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
{
int x;
scanf("%d", &x);
s[i] = s[i - 1] + x - 100;
}
int top = 0,res = 0;
stk[++ top] = 0;
for(int i = 1; i <= n; i ++)
{
if(s[stk[top]] > s[i]) stk[++ top] = i;
else if(s[stk[top]] < s[i])
{
int l = 0, r = top;
while(l < r)
{
int mid = l + r >> 1;
if(s[stk[mid]] < s[i]) r = mid;
else l = mid + 1;
}
res = max(res, i - stk[r]);
}
}
printf("%d\n", res);
return 0;
}
分析 - LeetCode T4
class Solution {
public:
typedef long long LL;
long long countSubarrays(vector<int>& nums, long long k) {
LL res = 0, sum = 0;
for(int i = 0, j = 0; j < nums.size(); j ++)
{
sum += nums[j];
while(sum * (j - i + 1) >= k) sum -= nums[i ++];
res += j - i + 1;
}
return res;
}
};
边栏推荐
- “薪資倒掛”、“畢業生平替” 這些現象說明測試行業已經...
- Hologres query management and timeout processing
- Innovation leads the direction. Huawei Smart Life launches new products in the whole scene
- 两个数相互替换
- 兩個數相互替換
- 2022.07.03 (lc_6111_counts the number of ways to place houses)
- (script) one click deployment of any version of redis - the way to build a dream
- Apifox (postman + swagger + mock + JMeter), an artifact of full stack development and efficiency improvement
- Multilingual Wikipedia website source code development part II
- 【纯音听力测试】基于MATLAB的纯音听力测试系统
猜你喜欢
Postman automatically fills headers
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Reasons and solutions of redis cache penetration and avalanche
What did I pay for it transfer to testing post from confusion to firmness?
Talking about JVM 4: class loading mechanism
Several simplified forms of lambda expression
2022.07.03 (lc_6111_counts the number of ways to place houses)
ORB(Oriented FAST and Rotated BRIEF)
Daily question brushing record (13)
POAP:NFT的采用入口?
随机推荐
I was beaten by the interviewer because I didn't understand the sorting
SAP ui5 application development tutorial 106 - how to improve the readability of SAP ui5 application routing URL trial version
【海浪建模3】三维随机真实海浪建模以及海浪发电机建模matlab仿真
Safety learning week4
npm install报错 强制安装
全栈开发提效神器——ApiFox(Postman + Swagger + Mock + JMeter)
抓包整理外篇——————状态栏[ 四]
Which financial products with stable income are good
Parameter passing mechanism of member methods
Paper notes multi UAV collaborative monolithic slam
Operator explanation
那些一门心思研究自动化测试的人,最后都怎样了?
How to use words to describe breaking change in Spartacus UI of SAP e-commerce cloud
Relationship between classes and objects
两个数相互替换
dotnet-exec 0.6.0 released
Single step debugging of master data reading of SAP commerce cloud products
资深测试/开发程序员写下无bug?资历(枷锁)不要惧怕错误......
[error reporting] "typeerror: cannot read properties of undefined (reading 'split')“
Arbitrum:二维费用