当前位置: 首页 > news >正文

2026-01-02

CF

Problem - 855B - Codeforces(1500)(前后缀)

题意: 已知\(p,q,r\),要求找到\(a_i,a_j,a_k\),满足\(i\leq j\leq k\) ,使得\(x=p\times a_i+q\times a_j+r\times a_k\) ,为最大值
遍历找前缀和后缀最大值,时间复杂度\(O(n)\)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;
LL a[N], b[N], c[N];int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n,p,q,r;cin >> n >> p >> q >> r;for (int i = 1; i <= n;i++){cin >> a[i];b[i] = a[i] * q;c[i] = a[i] * r;a[i] *= p;}for (int i = 2; i <= n;i++){a[i] = max(a[i], a[i - 1]);}for (int i = n - 1; i >= 1;i--){c[i]=max(c[i],c[i+1]);}LL ans = a[1] + b[1] + c[1];for (int i = 2; i <= n;i++){ans = max(ans, a[i] + b[i] + c[i]);}cout << ans << endl;
}

Problem - 788A - Codeforces(dp好题)

\(f[i][0]\):第 \(i\) 位为+;\(f[i][1]\):第 \(i\) 位为-

注意:d数组是差值,大小从1到n-1

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=1e5+10;
LL a[N], d[N],f[N][2];int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;cin >> n;for (int i = 1; i <= n;i++){cin >> a[i];}n--;for (int i = 1; i <= n;i++){d[i] = abs(a[i] - a[i + 1]);//记得取绝对值}for (int i = 1; i <= n;i++){f[i][0] = max(f[i-1][1]+d[i],d[i]);f[i][1] = max(f[i - 1][0] - d[i], 0LL);}LL ans = 0;for (int i = 1; i <= n;i++){ans = max(ans, max(f[i][0], f[i][1]));}cout << ans << endl;
}

Problem - 597B - Codeforces

题意: 算能包含的最多线段数
思路:按照右值排序,然后贪心计算数量即可
注意:这里对于pair先输入second,再输入first,这样就可以直接排序
pair<int,int> a[N],对于pair来说,默认对first排序

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=5e5+10;
pair<int, int> a[N];int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;cin >> n;for (int i = 0; i < n;i++){cin >> a[i].second >> a[i].first;}sort(a, a + n);int ans = 0;int lst = 0;for (int i = 0; i < n;i++){if(lst<a[i].second){ans++;lst = a[i].first;}}cout << ans <<endl;
}
http://www.jsqmd.com/news/183477/

相关文章:

  • 手把手玩转含DG的33节点配电网模型
  • uniapp+springboot安卓外卖点餐系统 带商家小程序
  • 长城电脑合作前景:共同开拓党政军市场Sonic需求
  • MyBatisPlus分页插件助力VoxCPM-1.5-TTS-WEB-UI日志查询优化
  • uniapp+springboot博物馆预约小程序
  • AWS SDK for PHP - 云端开发的强大工具
  • uniapp+springboot电影院购票 选座小程序_kfsf
  • Sonic数字人视频生成器参数调优完全手册
  • LCS 哈希做法
  • uniapp+springboot短视频分享的微信小程序_wqda
  • Reddit社区发起Sonic数字人创意大赛奖金池达万美元
  • Sonic与Raspberry Pi摄像头联动实现语音问答机器人
  • uniapp+springboot宠物用品商城小程序
  • uniapp+springboot道理小说阅读器 书架小程序
  • 一些范畴论的必要基础
  • 导师推荐9个AI论文写作软件,助你轻松搞定研究生论文!
  • uniapp+springboot餐厅点餐微信小程序_q
  • 20260102 Miller-Rabin Pollard-Rho
  • 救命神器!继续教育AI论文网站TOP9:选对工具轻松过关
  • 实用指南:STM32外设学习-WDG看门狗-(学习笔记)
  • 个股投资策略
  • 完整教程:零基础入门 Vue.js:项目创建、组件开发与路由管理
  • uniapp+springboot毕业生就业去向数据填报小程序
  • 169_尚硅谷_二维数组使用和内存布局
  • GitHub镜像提升Sonic代码克隆效率,助力开发者快速上手
  • CF2032E Balanced - Link
  • Z源逆变器SVPWM调制的MATLAB仿真模型(提前导通,延迟关断)
  • 房地产展厅配备Sonic售楼小姐,24小时在线接待
  • 带负载转矩前馈补偿的永磁同步电机FOC 1.采用滑模负载转矩观测器,可快速准确观测到负载转矩
  • Vue 3 响应式进阶:掌握 toRef 与 toRefs,告别解构陷阱