C. Strong Password

给定一个字符串\(s\),一个密码的长度\(m\),下界字符串\(l\)和上界字符串\(r\),上下界字符串长度均为\(m\),且字符只在0~9范围内,上界字符串的第 \(i\) 位非严格大于下界字符串的第 \(i\) 位,密码的第 \(i\) 位需要位于 \([l_i, r_i]\) 内。问是否存在一个密码不是\(s\)的子序列?

\(1 \leq m \leq 10\)

\(1 \leq |s| \leq 3\times 10^5\)

题解:贪心 + 枚举

  • 因为\(m\)的范围比较小,所以我们不妨考虑枚举密码的每一位
  • 根据题意得知,第\(i\)位密码\(ch\)必须保证在\([l_i,r_i]\)范围内
  • 因为题目给出的是子序列,所以我们一旦选定了第\(i\)位密码为\(ch\),假设\(ch\)在\(s\)中存在且第一次出现的位置为\(pos\),那么第\(i+1\)位密码应该从\(s\)的第\(pos\)位之后开始搜索
  • 我们不妨设\(s\)的第\(pos\)位之后的部分字符串为\(t\)
  • 如果我们枚举到的密码在\(t\)中不存在,那么说明密码一定能被构造出来
  • 如果第\(i\)位密码的所有情况在\(t\)中都存在的话,我们贪心地选择\([l_i,r_i]\)中第一次出现且在\(s\)中下标最大的字符作为第\(i\)位密码
#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define rson id << 1 | 1
#define lson id << 1
#define int long long
#define mpk make_pair
#define endl '\n'
using namespace std;
typedef unsigned long long ULL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 2e5 + 10, M = 4e5 + 10; void solve()
{
string s;
cin >> s;
int m;
cin >> m;
string l, r;
cin >> l >> r;
bool flag = false;
int p = 0;
for (int i = 0; i < m; ++i)
{
int mx = 0;
for (char j = l[i]; j <= r[i]; ++j)
{
int t = s.find(j, p);
if (t == -1)
{
flag = true;
break;
}
mx = max(mx, t);
}
p = mx + 1;
if (flag)
{
cout << "YES" << endl;
return;
}
}
cout << "NO" << endl;
}
signed main(void)
{
Zeoy;
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}

D. Rating System

给定对局数\(n\),以及每个对局会使得\(rating\)的变化值\(a_i\),初始\(rating\)为\(0\)。问给定的低保线\(k\)(分数到\(k\)后无论\(rating\)怎么变不会低于\(k\))为多少时,\(n\)个对局后玩家的\(rating\)最高

题解:思维 + 最大后缀

  • 容易发现答案应该是前缀和\(pre_i\)中的一个,但是如果我们枚举所有的前缀和复杂度显然为\(O(n^2)\),所以我们不妨逆向思维来考虑这个问题
  • 设\(suf\_max_i\)为第\(i\)位之后的最大后缀,易得\(suf\_max[i] = max(suf[i+1],pre[n]-pre[i])\)
  • 我们手模发现,对于任意一个\(k = pre_i\),最终的\(rating\)为\(pre_i + suf\_max_i\)
  • 这样的话,时间复杂度为\(O(n)\)
#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define rson id << 1 | 1
#define lson id << 1
#define int long long
#define mpk make_pair
#define endl '\n'
using namespace std;
typedef unsigned long long ULL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 3e5 + 10, M = 4e5 + 10; int n;
int a[N];
int pre[N]; void solve()
{
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= n; ++i)
pre[i] = pre[i - 1] + a[i];
vector<int> suf_max(n + 10);
for (int i = n; i >= 0; i--)
suf_max[i] = max(suf_max[i + 1], pre[n] - pre[i]);
int k = 0;
for (int i = 1; i <= n; ++i)
{
if (pre[k] + suf_max[k] < pre[i] + suf_max[i])
k = i;
}
cout << max(0LL, pre[k]) << endl;
}
signed main(void)
{
Zeoy;
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}

Educational Codeforces Round 151 (Rated for Div的更多相关文章

  1. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  3. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  4. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  5. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  8. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

  9. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

  10. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

随机推荐

  1. PYRAFORMER: 用于长时间序列建模和预测的低复杂度金字塔注意力《PYRAFORMER: LOW-COMPLEXITY PYRAMIDAL ATTENTION FOR LONG-RANGE TIME SERIES MODELING AND FORECASTING》(金字塔注意力模块机制、PAM、CSCM、多尺度)

    今天是2022年10月1日,今天重读一遍这篇论文. 10月1日16:48,上次读是4月20日,时间过得好快. 论文:PYRAFORMER: LOW-COMPLEXITY PYRAMIDAL ATTEN ...

  2. VS Code – Keyboard Shortcuts

    前言 记入一些自己常用到的 Keyboard Shortcuts 和 Extensions. Keyboard Shortcuts undo redo 鼠标坐标:shift + left/right ...

  3. Angular 学习笔记 (Typescript 高级篇)

    由于 typescript 越来越复杂. 所以特意开多一个篇幅来记入一些比较难的, 和一些到了一定程度需要知道的基础. 主要参考 https://basarat.gitbook.io/typescri ...

  4. [TK] 矩阵取数游戏<简单版> hzoi-tg-906-2

    本题是一个坐标DP问题 状态转移 首先我们注意到,一个状态只能由两种前置状态得到:取左边的数和取右边的数,因此我们以状态为阶段定义如下: \(f[a][b][c]\) 为状态转移数组,其中 \(a\) ...

  5. [OI] 欢夏!邪龙?马拉车!

    标题来自原神 算法概述 Manacher 算法 用途:寻找回文串,最板子的情况下用于字符串的回文子串计数 给定一个字符串 \(S\),求出它全部的回文子串 容易想到一种暴力的 \(n^{2}\) 做法 ...

  6. 第42天:WEB攻防-PHP应用&MYSQL架构&SQL注入&跨库查询&文件读写&权限操作 - 快捷方式

    接受的参数值未进行过滤直接带入SQL查询 MYSQL注入:(目的获取当前web权限) 1.判断常见四个信息(系统,用户,数据库名,版本) 2.根据四个信息去选择方案 root用户:先测试读写,后测试获 ...

  7. 采集数据产品描述有超链接///设置免运费后,达到免送标准,其他运费不显示///给产品详情页面的图片点击放大是个模态窗///在shop页面有重复的产品展示,去重

    //产品描述有超链接,去掉 function remove_product_hyperlinks($content) { if (is_product()) { // 确保只在产品页面上应用 $con ...

  8. es6有哪些新特性?

    1. let 和 ocnst ,可以定义块级作用域 2. 新增了箭头函数,箭头函数简化了函数定义的定义 3.新增了promise解决回调地狱问题 ps:回调地狱是我们异步请求服务器数据时,通过then ...

  9. 双通道MIL-STD-1553B总线通讯模块

    * 双通道MIL-STD-1553B总线通讯模块 * 32bi,33 MHz  CPCI/PCI/总线* 每个通道为A.B双冗余总线* 单功能可设置BC/RT/BM一种工作模式* 数据传输率: 4Mb ...

  10. 6.19 成都站云原生 Meetup,KubeSphere 和 APISIX 等你来!

    以容器技术和容器编排为基础的云原生应用,被越来越多的企业用户接受和使用,并且在生产环境中使用容器技术的比例逐年增加.KubeSphere 作为一款面向应用的开源容器混合云,经过 3 年的发展和 10 ...