题意:给出一个字符串s, 可以从左往右拿走s的字符, 至少要到s的第几个位置才能拼成t

思路:用二维数组记录前缀,然后二分即可.

 #include<bits/stdc++.h>

 using namespace std;
#define inf 5000000
#define N 210050
int sum[N][];
int arr[];
string s;
string str;
int n;
bool slove(int id) {
for(int i=; i<; i++)
if(arr[i]-sum[id][i]>)
return false;
return true;
}
int main() {
cin>>n;
cin>>str;
int _;
cin>>_;
for(int i=; i<str.size(); i++) {
++sum[i][str[i]-'a'];
if(i!=) {
for(int j=; j<; j++) {
sum[i][j]+=sum[i-][j];
}
}
}
while(_--) {
cin>>s;
for(int i=; i<=; i++)
arr[i]=;
for(int i=; i<s.size(); i++) {
arr[s[i]-'a']++;
}
int l=;
int r=n;
int ans=inf;
while(l<=r) {
int mid=(l+r)/;
if(slove(mid)) {
r=mid-;
ans=min(ans,mid);
} else {
l=mid+;
}
}
cout<<ans+<<'\n';
}
return ;
}

Educational Codeforces Round 67 (Rated for Div. 2) B题【前缀+二分】【补题ING系列】的更多相关文章

  1. Educational Codeforces Round 67 (Rated for Div. 2)

    A 考虑之前选中没有一个的,那么结果就是\(min(n-s,n-t)\) 那么能选中的第一次就是这个结果\(+1\),但需要拥有两个 \((s>t)\)考虑一开始选不中\(t\),则但选中\(t ...

  2. Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题

    A. Two Rival Students There are

  3. Educational Codeforces Round 94 (Rated for Div. 2) A. String Similarity (构造水题)

    题意:给你一个长度为\(2*n-1\)的字符串\(s\),让你构造一个长度为\(n\)的字符串,使得构造的字符串中有相同位置的字符等于\(s[1..n],s[2..n+1],...,s[n,2n-1] ...

  4. 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 ...

  5. 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 ...

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

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

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

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

  8. 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 ...

  9. 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 ...

随机推荐

  1. JWT 身份认证优缺点分析以及常见问题解决方案

    本文转载自:JWT 身份认证优缺点分析以及常见问题解决方案 Token 认证的优势 相比于 Session 认证的方式来说,使用 token 进行身份认证主要有下面三个优势: 1.无状态 token ...

  2. pandas之分组计算笔记

    分组计算三部曲:拆分-->应用-->合并 分组:就是按照行或列把相同索引的部分分到一起 分组的关键词为groupby,分组后我们就可以对每组数据进行同一操作,返回的是每组数据分别计算后的结 ...

  3. Vs code 下设置python tasks.json

    { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.jso ...

  4. LinearSearch Java

    Java LinearSearch /** * <html> * <body> * <P> Copyright 1994-2018 JasonInternation ...

  5. babel-plugin-transform-remove-strict-mode

    场景:在VUE项目中,需要用到横向滚动条,在引入MUI相关的组件后,模板中的代码如下 在控制台中报错 报错内容说的是在严格模式下(strict mode)类型错误 经过推测,觉得可能是mui.js中用 ...

  6. 用python在屏幕上输出一个杨辉三角

    在屏幕上输出一个杨辉三角,代码如下 def yanghui(): L = [1] while True: yield L L.append(0) L = [L[i - 1] + L[i] for i ...

  7. 19C imp 导入合并表空间

    因为项目需要从9i 导数据到18C,所以发现如下特性 1.18C imp 导入数据,如果表空间在目标库没有,会将表导入到用户默认表空间 2.18C imp 导入数据,如果表空间在目标库有,但缺少权限. ...

  8. Image Processing and Analysis_8_Edge Detection:Edge and line oriented contour detection State of the art ——2011

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  9. 【问题】Difference between ">/dev/null 2>&1" and "2>&1 >/dev/null"

    https://www.unix.com/shell-programming-and-scripting/125947-difference-between-dev-null-2-1-2-1-dev- ...

  10. 解决pynq联网问题

    注:本文只在一种环境下实验!不一定能适用很多环境 一.由于校园网的限制,pynq之间连接路由器存在无法联网的情况! 因此本文主要针对需要登录认证问题提供一种解决方案: 网络环境:校园网络 网络登录:锐 ...