Problem - C - Codeforces

看清题目要求, 最重要部分在第二段. 大佬最后给出的代码果然简单, 思路简单化, 未必非要把答案在一个大括号里全部完成, 两个指针同时跑,中间加了一堆判断处理, 反而不如返璞归真, 简单清晰为后面改代码也省了很多力气

AC代码

#include <iostream>
#include <algorithm> using namespace std; typedef long long LL;
const int N = 2e5+10;
int q[N], h[N]; int main(){ int n, m;
string s1, s2;
cin >> n >> m >> s1 >> s2;
int res = 0; for(int i = 0, j = 0; i < n; i ++)
if(s1[i] == s2[j]) q[j ++] = i; for(int i = n-1, j = m-1; i >= 0; i --)
if(s1[i] == s2[j]) h[j --] = i; for(int i = 0; i < m; i ++) res = max(res, h[i+1]-q[i]);
cout <<res <<endl;
return 0;
}

Codeforces Round #704 (Div. 2), problem: (C) Maximum width还是要多学习的更多相关文章

  1. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

  2. Codeforces Round #704 (Div. 2)

    A. Three swimmers 题意:第一个人跳水是每隔a分钟去一次,第二个人跳水是每隔b分钟,第三个人跳水是每隔c分钟,一个人准备在p分钟的 时候去跳水,问需要最少等待多长时间才能轮到前三个人 ...

  3. Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和

    The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...

  4. Codeforces Round #425 (Div. 2) Problem D Misha, Grisha and Underground (Codeforces 832D) - 树链剖分 - 树状数组

    Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations ...

  5. Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论

    n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...

  6. Codeforces Round #753 (Div. 3), problem: (D) Blue-Red Permutation

    还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com) 传送门  Problem - D - Codeforces 题意 n个数字,n ...

  7. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  8. Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分

    Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...

  9. Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学

    — This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...

随机推荐

  1. python3生成一个含有20个随机数的列表,要求所有元素不相同,并且每个元素的值介于1到100之间

    import random alist = random.sample(range(1,101),20) #random.sample()生成不相同的随机数 print(alist)

  2. 字符串的高级应用-char a[100] = "1+2=;3-2=;2*5=;8/4=;" 得到char a[100] ="1+2=3;3-2=1;2*5=10;8/4=2;"

    1 #include<stdio.h> 2 #include<string.h> 3 4 int main() 5 { 6 char a[100] = "1+2=;3 ...

  3. ARM中断与架构知识 精简知识点

    目录 一.ARM系统的异常与中断 二.CPU模式与寄存器 1.ARM CPU模式 2.ARM CPU state,两种指令集 3.ARM CPU寄存器: 引申介绍一下存储空间中的数据存放 4.ARM三 ...

  4. 自定义 Django admin 组件

    摘要:学习 Django admin 组件,仿照源码的逻辑,自定义了一个简易的 stark 组件,实现类似 admin 的功能. 可自动生成 url 路由,对于model 有与之相应的配置类对象,可进 ...

  5. python写一个数字字典生成器

    #数字字典生成器 by qianxiao996 #博客地址:https://blog.csdn.net/qq_36374896 #此程序输入开始结束和位数即可在程序所在目录下生成字典 #只支持数字生成 ...

  6. java继承:extends

    继承:extends 1.java只支持单继承,不支持多继承 2.java支持多层继承(继承体系) 3.子类不能继承父类所有非私有的成员(成员方法和成员变量) 4.子类不能继承父类的构造方法,但是可以 ...

  7. 什么是unzip 命令?

        · 解压 *.zip 文件:unzip test.zip .    · 查看 *.zip 文件的内容:unzip -l jasper.zip .

  8. Spring-boot-菜鸟-properties配置

    如果测试结果出现中文乱码: 结果": Person{lastName='张胜男', age=11, boss=false, birth=Wed Nov 11 00:00:00 CST 202 ...

  9. sp-MVC-ideabaok

    直接通过初始化器创建 或者通过创建maven工程在自己添加需要的东西 配置 dispatcher-servlet.xml 包括扫描加载包: <context:component-scan bas ...

  10. SqlMapConfig.xml文件详解

    SqlMapConfig.xml 是 mybatis 的全局配置文件,配置内容如下: properties(属性) settings(全局配置参数) typeAliases(类型别名) typeHan ...