首页 > 其他分享 >Educational Codeforces Round 151 (Rated for Div

Educational Codeforces Round 151 (Rated for Div

时间:2023-06-30 13:24:59浏览次数:38  
标签:151 pre Educational Rated const suf int max 密码

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\)
  • image-20230630130717532
  • 这样的话,时间复杂度为\(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;
}

标签:151,pre,Educational,Rated,const,suf,int,max,密码
From: https://www.cnblogs.com/Zeoy-kkk/p/17516452.html

相关文章

  • CodeTON Round 5 (Div. 1 + Div. 2, Rated, Prizes!) D. Tenzing and His Animal Fri
    题面是真的抽象,翻译为人话之后大概就是,对于每个选择的集合当中,1必须选,n一定不能选,每个限制条件的意思是如果u和v不在一个集合里则最能玩y时间,则u或v独自玩最多玩y时间如果在同一集合则可以玩无限时间因此如果n和1不连通的话则一定为inf,否则的话就一定有限制,因为n一定不能选,则和......
  • CodeTON Round 5 (Div. 1 + Div. 2, Rated, Prizes!) C. Tenzing and Balls
    一开始以为是贪心,后来发现不好贪于是选择了dp,但是dp有个小细节没注意到,后面wa了几发我们以状态来分,f[i]表示考虑i的最大区间合长度,每次转移的时候考虑两种情况,一种是a[i]前面有一样的数字,比较选了a[i]和不选a[i]两种情况下的最大值,还有一种就是a[i]为第一个出现的数字则选区间长......
  • Educational Codeforces Round 150 (Rated for Div. 2) A-E
    比赛链接A代码#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;boolsolve(){intn;cin>>n;if(n<=4)cout<<"Bob"<<'\n';elsecout<<"Alice"<<......
  • Automatic quality of generated text Evaluation for Large Language Models,针对大模
    一、LLM生成结果自动化评测的技术挑战和研发背景LargeLanguageModels(LLMs)haverecentlygrownrapidlyandtheyhavethepotentialtoleadtheAItransformation.ItiscriticaltoevaluateLLMsaccuratelybecause: Highqualityrequirementsforgenerativere......
  • 论文阅读 | Soteria: Provable Defense against Privacy Leakage in Federated Learni
    Soteria:基于表示的联邦学习中可证明的隐私泄露防御https://ieeexplore.ieee.org/document/95781923FL隐私泄露的根本原因3.1FL中的表示层信息泄露问题设置在FL中,有多个设备和一个中央服务器。服务器协调FL进程,其中每个参与设备仅与服务器通信本地模型参数,同时保持其本地......
  • CF1515G Phoenix and Odometers
    有点神仙的。题意给定一张\(n\)个点\(m\)条边的有向图,有边权,进行\(q\)次询问(\(n,m,q\le2\times10^5\),边权为不超过\(10^9\)的正整数)。每次询问给定三个参数\(v,s,t(0\les<t\le10^9)\),你需要回答是否存在一条起点终点均为\(v\)的路径,满足\(\text{路径长}+s\equi......
  • Educational Codeforces Round 82 (Rated for Div. 2)_A. Erasing Zeroes(C++_模拟)
    Youaregivenastring.Eachcharacteriseither0or1.Youwantall1’sinthestringtoformacontiguoussubsegment.Forexample,ifthestringis0,1,00111or01111100,thenall1’sformacontiguoussubsegment,andifthestringis0101,100001o......
  • 题解:【AT Educational DP Contest-O】 Matching
    题目链接来点位运算优化,目前也是拿下了洛谷最优解,比第二名快一倍:#include<bits/stdc++.h>#defineintlonglong#definebtp(x)__builtin_popcount(x)#definelowbit(x)((x)&(-x))usingnamespacestd;namespaceFastIO{template<typenameT=int>inlineTread()......
  • Educational Codeforces Round 150 (Rated for Div. 2) C. Ranom Numbers
    #include<iostream>#include<string>#include<cstring>#include<algorithm>#include<cmath>usingnamespacestd;constintN=2e5+10;typedeflonglongll;//记录每个字母的最前面的位置和最后面的位置intFast[5],End[5];strings,c;llres=-0x3......
  • Educational Codeforces Round 150 (Rated for Div. 2) B. Keep it Beautiful
    #include<iostream>#include<cstring>usingnamespacestd;constintN=2e5+10;inta[N],res[N];intt;intmain(){ cin>>t; while(t--){ intn; cin>>n; for(inti=0;i<n;i++){ cin>>a[i]; } intk=a[0]; res[0]=......