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

2025.2.17——1400

2025.2.17——1400


A 1400

B 1400

C 1400

------------------------------------------------

  • 二分+构造+字符串/贪心/思维。CF的题就得多看透几层表面发掘本质。


A

  1. 一眼单调性。
  2. 分析后可以二分答案。

B

  1. 本质是: ( j − i ) ∣ n , s [ i ] ! = s [ j ] (j-i)|n,s[i]!=s[j] (ji)n,s[i]!=s[j] 。设想一个周期为 T T T
  2. 设最小的不能被 n n n 整除的数为 t t t 。必要性: T > = t T>=t T>=t 。充分性: T = = t T==t T==t 时, s [ i ] = = s [ j ] s[i]==s[j] s[i]==s[j]的距离为 t t t 的倍数,不能被 n n n 整除,满足题意。
  3. 绝妙的构造…

C

  1. 字符串贪心匹配。看着题解想了好久,值得多几次回味。解法和优化亦多样,正难则反/搜索/动态规划…

------------------------代码------------------------

A

#include <bits/stdc++.h>
#define int long long
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC)               \
    {                           \
        for (auto Vec : VEC)    \
            cout << Vec << ' '; \
        cout << '\n';           \
    }

void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    sort(begin(a) + 1, end(a));
    // bugv(a);

    auto ok = [&](int x)
    {
        int cnt = 0;
        // bug2(1, x);
        for (int i = 1; i <= n;)
        {
            int j = i;
            cnt++;
            for (; j <= n && a[j] - a[i] <= x << 1; j++)
                ;
            i = j;
            // bug(i);
        }
        // bug2(2, cnt);
        return cnt <= 3;
    };
    // ok(2);
    int l = -1, r = 1e9;
    while (r - l - 1)
    {
        int mid = l + r >> 1;
        if (ok(mid))
            r = mid;
        else
            l = mid;
    }
    cout << r << '\n';
}

B

#include <bits/stdc++.h>
#define int long long
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC)               \
    {                           \
        for (auto Vec : VEC)    \
            cout << Vec << ' '; \
        cout << '\n';           \
    }

void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n;
    cin >> n;
    int st = 1;
    while (n % st == 0)
        st++;
    for (int i = 0; i < n; i++)
        cout << (char)('a' + i % st);
    cout << '\n';
}

C

#include <bits/stdc++.h>
#define int long long
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC)               \
    {                           \
        for (auto Vec : VEC)    \
            cout << Vec << ' '; \
        cout << '\n';           \
    }

void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    string s;
    cin >> s;
    int m;
    cin >> m;
    string l, r;
    cin >> l >> r;
    int st = 0;
    int n = s.size();
    s = ' ' + s;
    for (int i = 0; i < m; i++)
    {
        int mx = st + 1;
        for (int j = l[i] - '0'; j <= r[i] - '0'; j++)
        {
            int t = st + 1;
            while (t <= n && j != s[t] - '0')
                t++;
            mx = max(mx, t);
        }
        st = mx;
    }
    cout << (st > n ? "YES" : "NO") << '\n';
}

相关文章:

  • CHARMM-GUI EnzyDocker: 一个基于网络的用于酶中多个反应状态的蛋白质 - 配体对接的计算平台
  • 【Leetcode 热题 100】1287. 有序数组中出现次数超过25%的元素
  • 利用雪花算法+Redis 自增 ID,生成订单号
  • java练习(28)
  • Java 大视界 -- 开源社区对 Java 大数据发展的推动与贡献(91)
  • AWS 前端自动化部署流程指南
  • Leetcode 526 Beautiful number
  • 用自己的数据训练yolov11目标检测
  • HTTP 响应头信息
  • Selenium+Pytest自动化测试框架实战
  • ad原理图元件透明问题
  • WWW 2025 | 中南、微软提出端到端双重动态推荐模型,释放LLM在序列推荐中的潜力...
  • 开源模型应用落地-LangGraph101-探索 LangGraph 短期记忆
  • 基于YOLO11深度学习的胃肠道息肉智能检测分割与诊断系统【python源码+Pyqt5界面+数据集+训练代码】深度学习实战、目标分割、人工智能
  • Java 基于SpringBoot+Vue 的旅游网站信息化管理系统设计与实现
  • JavaScript的诞生与进化
  • jetson orin nano super AI模型部署之路(一)deepseek r1模型部署
  • 【ProtoBuf】文件编写及序列化
  • C语言实现的常见排序算法
  • AI与大数据:双剑合璧的智能革命
  • NFL球员将参加洛杉矶奥运会腰旗橄榄球比赛
  • 中铁城市发展投资集团原党委书记、董事长黄天德被查
  • 焦点访谈丨售假手段又翻新,警惕化肥“忽悠团”的坑农套路
  • 上海国际电影电视节 | 奔赴电影之城,开启光影新程
  • 春决火爆的背后,PEL如何做大这块电竞蛋糕
  • 国家发改委:不断完善稳就业稳经济的政策工具箱,确保必要时能够及时出台实施