cf1137b kmp

博客详细解析了如何运用KMP字符串匹配算法解决Codeforces Round #659 (Div. 2)中的一道题目CF1137B。内容涵盖了KMP算法的基本原理,包括部分匹配表的构造以及如何在主串中避免不必要的回溯,从而提高字符串查找效率。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

char s[500005];
char t[500005];
int nxt[500005];

void getn(char* p,int len)
{
    nxt[0]=-1;
    int i=0,j=-1;
    while(i<len)
    {
        if(j==-1 || p[i]==p[j])
        {
            i++;j++;
            nxt[i]=j;
        }
        else
            j=nxt[j];
    }
}

int main() {

    while(~scanf("%s",s))
    {
        scanf("%s",t);

        int len1=strlen(s),len2=strlen(t);

        getn(t,len2);

        int tp=nxt[len2];
        int s1=0,s0=0,t1=0,t0=0,d1=0,d0=0;

        for(int i=0;i<len1;i++)
            if(s[i]=='1')
                s1++;
            else
                s0++;

        for(int i=0;i<len2;i++)
            if(t[i]=='1')
                t1++;
            else
                t0++;

        for(int i=0;i<tp;i++)
            if(t[i]=='1')
                d1++;
            else
                d0++;

        d1=t1-d1;d0=t0-d0;

        if(!(s1<t1 || s0<t0))
        {
            s1-=t1;s0-=t0;
            cout<<t;
            while(s1>=d1 && s0>=d0)
            {
                s1-=d1;s0-=d0;
                for(int i=tp;i<len2;i++)
                    printf("%c",t[i]);
            }
        }

        while(!s1==0)
            cout<<'1',s1--;
        while(!s0==0)
            cout<<'0',s0--;

        cout<<endl;

    }
    return 0;
}

 

我用conda下载了mkl,我现在应该怎么用: libblas conda-forge/linux-64::libblas-3.9.0-35_h4a7cf45_openblas libcblas conda-forge/linux-64::libcblas-3.9.0-35_h0358290_openblas libgfortran conda-forge/linux-64::libgfortran-15.1.0-h69a702a_5 libgfortran5 conda-forge/linux-64::libgfortran5-15.1.0-hcea5267_5 libhwloc conda-forge/linux-64::libhwloc-2.12.1-default_h7f8ec31_1002 libiconv conda-forge/linux-64::libiconv-1.18-h3b78370_2 liblapack conda-forge/linux-64::liblapack-3.9.0-35_h47877c9_openblas libopenblas conda-forge/linux-64::libopenblas-0.3.30-pthreads_h94d23a6_2 libstdcxx conda-forge/linux-64::libstdcxx-15.1.0-h8f9b012_5 libstdcxx-ng conda-forge/linux-64::libstdcxx-ng-15.1.0-h4852527_5 libxml2 conda-forge/linux-64::libxml2-2.14.6-h26afc86_2 libxml2-16 conda-forge/linux-64::libxml2-16-2.14.6-ha9997c6_2 llvm-openmp conda-forge/linux-64::llvm-openmp-21.1.0-h4922eb0_0 mkl conda-forge/linux-64::mkl-2024.2.2-ha770c72_17 numpy conda-forge/linux-64::numpy-2.3.3-py311h2e04523_0 python_abi conda-forge/noarch::python_abi-3.11-8_cp311 scipy conda-forge/linux-64::scipy-1.16.2-py311h1e13796_0 tbb conda-forge/linux-64::tbb-2021.13.0-hb60516a_3 The following packages will be DOWNGRADED: _openmp_mutex 4.5-2_gnu --> 4.5-4_kmp_llvm Proceed ([y]/n)? y Downloading and Extracting Packages: Preparing transaction: done Verifying transaction: done (wan) root@dev-kunlin-yang-aieditor-1-6bnr-5b859cbcb8-zr88t:/data/colmap_build/colmap/build# cmake .. -GNinja -DBLA_VENDOR=Intel10_64lp -DCMAKE_CUDA_ARCHITECTURES=80 -- BUILD_SHARED_LIBS: OFF -- CMAKE_BUILD_TYPE: Release -- CMAKE_GENERATOR: Single-config -- CMAKE_GENERATOR: Ninja -- CMAKE_REGISTRY_FOLDER: OFF -- Could NOT find MKL (missing: MKL_LIBRARIES) CMake Error at /data/tool/opt/cmake-3.29.9-linux-x86_64/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find BLAS (missing: BLAS_LIBRARIES) Call Stack (most recent call first): /data/tool/opt/cmake-3.29.9-linux-x86_64/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE) /data/tool/opt/cmake-3.29.9-linux-x86_64/share/cmake-3.29/Modules/FindBLAS.cmake:1387 (find_package_handle_standard_args) /data/code/faiss-36b77353dc435383e0c23a709e7997a29d049041/faiss/CMakeLists.txt:396 (find_package) -- Configuring incomplete, errors occurred!
09-16
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值