T1
T2
emmm 今天的俩题都是简单if判断 所以另找了俩题,一道acwing周赛T2,一道力扣每日一题
T3:合格数

涉及到给一段区间标记的问题,大概率是考差分和前缀和
- #include
- using namespace std;
- const int N=2e5+10;
- int s[N];
- int d[N];
- int n,k,q;
- int main()
- {
- cin>>n>>k>>q;
- for(int i=0;i
- int l,r;
- cin>>l>>r;
- d[l]++,d[r+1]--;
- }
- for(int i=1;i<=N-10;i++){
- d[i]+=d[i-1];
- s[i]=s[i-1];
- if(d[i]>=k)s[i]++;
- }
- while(q--){
- int a,b;
- cin>>a>>b;
- cout<
-1]<- }
- return 0;
- }
T4:卖卖股票的最佳时机2
链接:
题目描述:
给你一个整数数组 prices ,其中 prices[i] 表示某支股票第 i 天的价格。
在每一天,你可以决定是否购买和/或出售股票。你在任何时候 最多 只能持有 一股 股票。你也可以先购买,然后在 同一天 出售。
返回 你能获得的 最大 利润 。

因为同一天也能卖出的条件
就可以用贪心的策略,只要后一天的价格比当前天高,那就能获得利润
-
- class Solution{
- public:
- int maxProfit(vector<int>& prices){
- int ans=0;
- int n=prices.size();
- for(int i=0;i
-1;i++){ - if(prices[i]
1]){ - ans+=prices[i+1]-prices[i];
- }
- }
- return ans;
- }
- };
进程空间地址,启动!
-
相关阅读:
联邦学习综述三
测试--自动化测试selenium
位运算及其应用
gulimall基础篇回顾Day-13
【JAVASE】面向对象的三大特征
京东前端经典react面试题合集
树状数组及其拓展
nginx限流 漏桶与令牌桶
pkg 打包 nodejs
统计无向图中无法互相到达点对数
-
原文地址:https://blog.csdn.net/m0_64263546/article/details/133495121