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

2025-11-15

Problem - 1858B - Codeforces(1500)(贪心)

这题一个是要读题
在不包括cookie seller的区间才算没吃饼干的时间sum += (s[i] - s[i - 1] - 1) / d;
在加上路过cookie seller时吃的饼干数 sum += m - 1;
然后贪心的思想,遍历删除每个cookie seller
重新计算合并两个区间里吃的饼干数

注意一点,要再处理s[0]=1-ds[m+1]=n+1,这里就可以考虑到1~s[1]s[m]~n区间

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;void solve()
{int n, m, d;cin >> n >> m >> d;vector<int> s(m + 2);for (int i = 1; i<=m;i++){cin >> s[i];}s[0] = 1 - d;s[m + 1] = n + 1;int sum = 0;for (int i = 1; i <= m+1;i++){sum += (s[i] - s[i - 1] - 1) / d;}sum += m - 1;int ans = n + 1, cnt = 0;for (int i = 1; i <= m;i++){int res = sum;res -= (s[i] - s[i - 1] - 1) / d;res -= (s[i + 1] - s[i] - 1) / d;res += (s[i + 1] - s[i - 1] - 1) / d;if(res<ans){ans = res;cnt = 1;}else if(res==ans){cnt++;}}cout << ans << " " << cnt << endl;
}int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin >> T;while (T--){solve();}
}

Problem - 1385D - Codeforces(string)

分治思想,递归

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;
string s;
int getans(int l, int r, char c)
{if (l == r)return s[l] != c;//相等返回0int tot1 = 0, tot2 = 0;int mid = (l + r) >> 1;for (int i = l; i <= mid; i++)if (s[i] != c)tot1++;for (int i = mid + 1; i <= r; i++)if (s[i] != c)tot2++;tot1 += getans(mid + 1, r, c + 1);tot2 += getans(l, mid, c + 1);return min(tot1, tot2);
}void solve()
{int n;cin >> n >> s;cout << getans(0, n - 1, 'a') << endl;
}int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin >> T;while (T--){solve();}
}

Problem - 873B - Codeforces(01string)(1500)

这题思路简单,存第一次出现数字下标,然后求前缀长度即可

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;
int sum[N], f[N], ans;int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;cin >> n;string s;cin >> s;s = " " + s;for (int i = 1; i <= n;i++){sum[i] = sum[i - 1] + (s[i] == '1' ? 1 : -1);if(sum[i]==0){ans = max(ans, i);}}for (int i = 1; i <= n;i++){if(f[sum[i]+n])ans = max(ans, i - f[sum[i]+n]);elsef[sum[i]+n] = i;}cout << ans << endl;
}

昨天要做的洛谷题

P2347 [NOIP 1996 提高组] 砝码称重 - 洛谷

01背包问题

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=1010;
int a[N], x, num,ans;
int b[10] = {0, 1, 2, 3, 5, 10, 20};
bool vis[N];int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int x;for (int i = 1; i <= 6;i++){cin >> x;for (int j = 1; j <= x;j++)a[++num] = b[i];}vis[0] = 1;for (int i = 1; i <= num;i++){for (int j = 1000; j >= 0;j--)if(vis[j])vis[j + a[i]] = 1;}for (int i = 1; i <= 1000;i++){if(vis[i])ans++;}cout << "Total=" << ans << endl;
}

bitset解法
用二进制求方案数

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;
int a[10], w[10] = {1, 2, 3, 5, 10, 20};
bitset<1010> s;int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);for (int i = 0; i < 6;i++){cin >> a[i];}s[0] = 1;for (int i = 0; i < 6;i++){for (int j = 0; j < a[i];j++){s |= s << w[i];}}cout << "Total=" << s.count() - 1;
}
http://www.jsqmd.com/news/41299/

相关文章:

  • 2025.11.15博客
  • Pandas - read_html()
  • 实用指南:Linux企业级解决方案架构:字节跳动短视频推荐系统全链路实践
  • 实用指南:PyTorch DataLoader 高级用法
  • 简单做一个舒尔特方格小游戏
  • C语言新手怎么快速掌握
  • RSS and Atom
  • Wi-Fi FTM(Fine Timing Measurement)简介
  • 通用会话控制方案
  • LISTAGG 用于将多行数据聚合为单行字符串(拼接),而与其功能相反的需求是 将单行字符串按指定分隔符拆分为多行数据
  • ESP32 I2S音频总线学习笔记(八):添加按键控制功能 - 详解
  • 2025年8款AI论文写作神器推荐:轻松搞定毕业论文查重
  • 基于python的酒店管理系统_36rhk752(Pycharm Flask Django成品源码LW) - 详解
  • pythontip 从字典中删除一组键
  • Softmax 函数全面而详细的解读,原理、图像、应用 - 详解
  • 中级前端工程师详细技能清单
  • Atcoder FPS 24 记录
  • 扩展单调栈扫描线维护历史信息
  • 酵母单杂交 (Y1H):蛋白质 - DNA 互作研究的 基因解码器
  • ORACLE行记录转字符串用分隔符连接的两个函数:WM_CONCAT、LISTAGG
  • MySQL 8+ 日志管理与数据备份恢复实战指南 - 指南
  • 航运、应急、工业适用,AORO P1100三防平板引领行业数字化变革 - 详解
  • 20232419 2025-2026-1 《网络与系统攻防技术》实验五实验报告
  • 为什么高手写 CSS 都偏爱 rem?这三大优势无法拒绝
  • 完整教程:FPGA 49 ,Xilinx Vivado 软件术语解析(Vivado 界面常用英文字段详解,以及实际应用场景和注意事项 )
  • 前端css中rem的作用
  • 第三十天
  • WinDbg 随笔 001 —— HelloWorld + WinDbg
  • 数据结构2:单链表 - 教程
  • 20251115 - Hash 总结