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

2026-03-15

CF

Problem - 467C - Codeforces

选和不选简单dp

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define double long double
#define endl '\n'
const LL mod = 998244353;
const int N=5010;
LL a[N];
LL dp[N][N];int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n,m,k;cin >> n >> m >> k;for (int i = 1; i <= n;i++){cin >> a[i];}for (int i = 1; i <= n;i++){a[i] += a[i - 1];}for (int i = 1; i <= n; i++){for (int j = 1; j <= k; j++){if (i - m >= 0)dp[i][j] = max(dp[i - m][j - 1] + a[i] - a[i - m], dp[i - 1][j]);}}cout << dp[n][k] << endl;
}

Problem - 283A - Codeforces

模拟

[!warning] 一个注意点:

first ai elements = 前 ai 个元素
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define double long double
#define endl '\n'
const LL mod = 998244353;
const int N=2e5+10;
LL a[N], d[N];//注意,开 LL!!!int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;cin >> n;int op, x, y;LL ans = 0;int top = 1;while(n--){cin >> op;if(op==1){cin >> x >> y;d[x] += y;//后往前求和ans += x * y;}else if(op==2){cin >> x;a[++top] = x;ans += x;}else{ans -= a[top] + d[top];d[top - 1] += d[top];a[top] = 0, d[top] = 0, top--;}cout << fixed << setprecision(10) << ans * 1.0 / top << endl;}
}

Problem - 1991C - Codeforces

一道1300的构造,花了好久想
首先判断奇偶性,因为不管怎么减,奇偶性相反的数字始终是相反的
然后减去一个数,相当于把数组变成偶数(这里想了好久,一直想不懂,理解下来只是为了化简操作)
理解:把整个数组放到数轴上,固定0为最左的端点,每次虽然减去 \(2^i\) ,能保证整个数组处理之后,不会超过 \(2^i\) ,因为数组的变化实际上是变成距离 \(2^i\) 的大小

  1. 你的纸条长达 2^30
  2. 你捏住正中间的 2^29,往下拽成 V 字型,碰到桌面(高度变 0)。
  3. 两端的 02^30 翘到天上贴在一起,它们的高度都是 2^29
  4. 纸条上所有的数字,现在全被折进了 02^29 的高度里!
    下一轮,你再拿一把剪刀,把这个 V 字型的纸条从高度 2^28 的地方剪开,再捏住中间折一次……
    每折一次,最高的高度就矮一半!

所以一定保证数组会一直缩小,直到1或0
如果是奇数的话,只要进行31次,因为最后一次减去1之后,变成偶数0,不用再操作

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define double long double
#define endl '\n'
const LL mod = 998244353;
const int N=2e5+10;
int a[N];void solve()
{int n;cin >> n;for (int i = 0; i < n;i++){cin >> a[i];}bool flag = 0;for (int i = 1; i < n;i++){if(a[i]%2!=a[0]%2){flag = 1;break;}}if(flag){cout << -1 << endl;return;}cout << 32 << endl;cout << a[0] << " ";//想了好久for (int i = 29; i >= 0;i--){cout << (1 << i)<<" ";}cout << 1 << endl;
}int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin >> T;while (T--){solve();}
}

另一种写法(好理解的):

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define double long double
#define endl '\n'
const LL mod = 998244353;
const int N=2e5+10;
int a[N];void solve()
{int n;cin >> n;for (int i = 0; i < n;i++){cin >> a[i];}bool flag = 0;for (int i = 1; i < n;i++){if(a[i]%2!=a[0]%2){flag = 1;break;}}if(flag){cout << -1 << endl;return;}bool isodd = a[0] % 2;//补充if(isodd){cout << 30 << endl;}else{cout << 31 << endl;}for (int i = 29; i >= 0;i--){cout << (1 << i)<<" ";}if(isodd==0)cout << 1 << endl;
}int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin >> T;while (T--){solve();}
}

复习

输入输出

freopen("data.in","r",stdin);
freopen("data.out","w",stdout);

单调栈

P3467 [POI 2008] PLA-Postering - 洛谷

单调栈简单好题
单调递增

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define double long double
#define endl '\n'
const LL mod = 998244353;
const int N=2e5+10;int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;cin >> n;stack<int> s;int d, w;int cnt = 0;//可以合并的个数for (int i = 1; i <= n;i++){cin >> d >> w;while(!s.empty()&&w<=s.top()){if(w==s.top())cnt++;s.pop();}s.push(w);}cout << n - cnt << endl;
}

Problem - 1779D - Codeforces

只不过这个是凹,就是保持单调递减,然后找相等

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define double long double
#define endl '\n'
const LL mod = 998244353;
const int N=2e5+10;
int a[N], b[N];void solve()
{int n;map<int, int> mp;stack<int> s;cin >> n;for (int i = 0; i < n;i++){cin >> a[i];}for (int i = 0; i < n;i++){cin >> b[i];}int m;cin >> m;for (int i = 0; i < m;i++){int x;cin >> x;mp[x]++;}for (int i = 0; i < n;i++){while(!s.empty()&&s.top()<b[i])s.pop();if(a[i]<b[i]){cout << "NO\n";return;}if (a[i] == b[i] || (!s.empty() && s.top() == b[i]))continue;if(mp[b[i]]==0){cout << "NO\n";return;}s.push(b[i]);mp[b[i]]--;}cout << "YES\n";
}int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin >> T;while (T--){solve();}
}
http://www.jsqmd.com/news/480888/

相关文章:

  • 软件研发 --- ( pear-admin-flask 项目结构)Flask + Layui 项目标准开发模板
  • 2026年OMO模式电商零售系统优选,提升零售竞争力,县域数字化运营,OMO模式电商零售平台怎么选择 - 品牌推荐师
  • 分析50Ω空气线差分探头,哪家性价比高? - 工业推荐榜
  • Memos 备忘录的Markdown语法介绍
  • 2026不锈钢筛板定制风向标,口碑厂家实力推荐,目前不锈钢筛板技术领航,品质之选 - 品牌推荐师
  • UG NX中快速摆正零件视角的几种常用方法
  • NOP源码分析 二
  • NOP源码分析五---set的存储
  • 动态内存分配
  • 1018: 士兵排阵
  • 数据库优化(面试标准回答 + 博客版)
  • 2026年停车场管理服务推荐哪些,北京权威企业盘点 - mypinpai
  • 2026年国内不错的发际线种植品牌推荐,这几家值得关注!不剃发植发/发际线种植/发际线调整,发际线种植医院推荐哪些 - 品牌推荐师
  • NOP源码分析四
  • 盘点2026年口碑好的西服定制品牌,宁波郡狮手工高档结婚西服定制亮眼 - 工业品牌热点
  • 2026年低温同轴铜镍电缆什么品牌好,快来一起探讨 - 工业设备
  • 全网热议!2026年单北斗GNSS变形监测系统推荐榜单
  • 2026东莞机加工件厂家评测:这些厂家值得关注,链条导轨/垫条/铁氟龙加工件/聚乙烯导轨,机加工件厂家口碑推荐 - 品牌推荐师
  • 沃尔玛购物卡快速回收全流程! - 团团收购物卡回收
  • 使用 Certbot 为 Nginx 自动配置 SSL 证书
  • 洛谷(Luogu)上的题目难度标签对应为“入门”或“普及-”级别: 涵盖了数位处理、循环模拟和逻辑判断三大核心考点
  • 赶deadline必备!全领域适配的AI论文平台 —— 千笔·专业论文写作工具
  • 2026年混床设备厂商大起底:体外再生技术谁更优,净水设备/离子交换设备/电渗析器/反渗透设备,混床设备工厂排行 - 品牌推荐师
  • Nop源码分析三
  • NOP源码分析 一
  • 2026年Optomet激光测振仪总代理推荐,专业服务覆盖全国 - myqiye
  • 研究生必看!全场景通用的AI论文平台 —— 千笔写作工具
  • windows常用脚本
  • (leetcode)力扣100 96.只出现一次的数字(位运算)
  • 北京全脑速读记忆训练费用多少 天使英才性价比高吗 - 工业品网