首页 > 其他分享 >2025.1.5——1200

2025.1.5——1200

时间:2025-01-14 18:54:20浏览次数:1  
标签:------------------------ 2025.1 string int 1200 two sub

2025.1.5——1200


Q1. 1200

Kevin discovered a binary string $s$ that starts with 1 in the river at Moonlit River Park and handed it over to you. Your task is to select two non-empty substrings$^{\text{∗}}$ of $s$ (which can be overlapped) to maximize the XOR value of these two substrings.

The XOR of two binary strings $a$ and $b$ is defined as the result of the $\oplus$ operation applied to the two numbers obtained by interpreting $a$ and $b$ as binary numbers, with the leftmost bit representing the highest value. Here, $\oplus$ denotes the bitwise XOR operation.

The strings you choose may have leading zeros.

$^{\text{∗}}$A string $a$ is a substring of a string $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.


------------------------独自思考分割线------------------------

  • 2025年第一题...


A1.

  1. 1点就是需要发现两个字符串的长度
  2. 另一点就是考虑最大值要从高位考虑

------------------------代码分割线------------------------

A1.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
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
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    string s;
    cin >> s;
    int n = s.size();
    s = ' ' + s;
    int has = 1;
    int l = 1, r = n, sub_l = 1, sub_r = 1;
    string t;
    for (int i = 1; i <= n; i++)
        if (s[i] - s[1])
            has = 0;
    if (has)
    {
        cout << l << ' ' << r << ' ' << sub_l << ' ' << sub_r << endl;
        return;
    }

    int f = 0;

    for (int i = 2; i <= n; i++)
        if (!f)
        {
            if (s[i] == '0')
                t += '1', f = 1;
        }
        else
        {
            t += s[i] == '1' ? '0' : '1';
        }
    int m = t.size();
    int res = 0, real_l = 1;
    sub_r = sub_l + m - 1;
    for (; sub_r <= n; sub_l++, sub_r++)
    {
        int ans = 0;
        for (int i = sub_l, j = i - sub_l; i <= sub_r; i++, j++)
            if (s[i] == t[j])
                ans++;
            else
                break;
        if (ans > res)
        {
            res = ans;
            real_l = sub_l;
        }
    }
    sub_l = real_l;
    sub_r = sub_l + m - 1;
    cout << l << ' ' << r << ' ' << sub_l << ' ' << sub_r << endl;
}

标签:------------------------,2025.1,string,int,1200,two,sub
From: https://www.cnblogs.com/jkkk/p/18671405

相关文章

  • 施耐德 三菱 西门子PLC 以太网口S7-1200/1500系列通讯协议解析说明文档
       资料参考链接:https://item.taobao.com/item.htm?abbucket=1&id=766532329733&ns=1&pisk=g0VseN0PDhxsC5j0KlbEVm4PVjhjhw5yfEgYrrdwkfhtDJaucc7cIfyIckEIXC7GIxnbjfH0QmoZcja0VwSPa_zgSjcR4g5yCEod7bAxWqKqv23rGVC1T97TSjcA4eRAU_ag2s7Opd3xJwgqlFnYDAhpvVoKWd......
  • 2025.1.10(MyBatis知识点)
    多条件查询方式一:使用#{arg0}-#{argn}或者#{param1}-#{paramn}获取接口请求参数方式二:使用注解,接口中引入@Param(“name”)注解,再在配置文件中#{name}获取参数方式三:使用pojo对象传递参数,配置文件中按照实体类的属性获取参数模糊查询select*fromuserwhe......
  • 2025.1.8
    代数学基础拉表知识点状态辗转相除法完成一轮对称多项式完成一轮综合除法+贝祖小定理完成一轮拉格朗日插值完成一轮艾森斯坦判别法完成一轮群环域基本概念子群、子环、子域整环带参数的方程组行列式算递推函数求解矩阵方程......
  • Docker更换镜像源(2025.1最新可用镜像,全网最详细)
    文章目录前言可用镜像源汇总换源方法1-临时换源换源方法2-永久换源(推荐)常见问题及对应解决方案补充1.如何测试镜像源是否可用换源速通版(可以直接无脑复制粘贴)前言由于各种网络政策,在国内访问DockerHub速度会非常缓慢,大家一般都会采取更换镜像源的方式来进行加速。......
  • 2025.1.8 练习赛总结
    总览本文同步发表与:洛谷:https://www.luogu.com.cn/article/hdzdhnif。博客园:<>。打得不好,在赛时只做了A题。昨晚的睡眠使我刚好处于困和不困的叠加态,导致想题的时候脑子极乱。A:Gym103430F。B:CF578B。C:CF1407D。D:洛谷P11122。E:CF1208D。A-Gym103430F-X-Mag......
  • 2025.1.8 鲜花
    Nim的变种グランドエスケープ空飛ぶ羽根と引き換えに繋ぎ合う手を選んだ僕ら没有选择飞翔的翅膀而是选择十指相扣的我们それでも空に魅せられて夢を重ねるのは罪か却仍然向往着天空反复做着同样的梦这有错吗夏は秋の背中を見てその顔を思い浮かべる夏天望着秋天......
  • 笔记 2025.1.6:计数问题选讲-徐哲晨
    目录P4463[集训队互测2012]calc(拉插优化dp)P4484[BJWC2018]最长上升子序列(状压dp)ARC138E-DecreasingSubsequence(构造双射)P5400[CTS2019]随机立方体(二项式反演)AGC064D-RedandBlueChips(构造充要条件)CF1942G.BessieandCards(反射容斥)CF1874F.JellyfishandOEIS(容......
  • 2025.1.6-3 Linux虚拟机网络配置
    VMware有三种主要的网络配置模式,分别为桥接模式(用的最多)、NAT模式(用的少)和仅主机(基本不用)模式。每种模式都有其特点和适用场景,以下为你详细介绍:1.桥接模式(Bridged)(最重要)原理:在桥接模式下,虚拟机的虚拟网卡会与主机的物理网卡进行桥接,虚拟机就如同局域网中的一台独立物理......
  • 2025.1.5
    BuyOne,GetOneFree题解OneLastKiss&BeautifulWorld初めてのルーブルはなんてことはなかったわ私だけのモナリザもうとっくに出会ってたから初めてあなたを見たあの日動き出した歯車止められない喪失の予感もういっぱいあるけれどもう一つ増やしましょう(Can......
  • 2025.1 洛谷月赛选练
    众所周知,洛谷月赛的题目质量其实是很高的。会不了一点。应该只会做绿及以上。紫及以上会标上[HardProblem]的标签。题目选自洛谷2023官方题单(1-4月)P8941[DTOI2023]D.Goodbye2022P8966觅光|SearchingforHope(easyver.)P8967追寻|PursuitofDream[HardP......