随意凯


私信TA

用户名:tangjiakai

访问量:1475

签 名:

等  级
排  名 10376
经  验 1033
参赛次数 0
文章发表 2
年  龄 0
在职情况 学生
学  校 武汉理工大学
专  业

  自我简介:

解题思路: 看代码就行 很简单。。

注意事项: 注意 答案可能超过int型,需要long long

参考代码:

#include <iostream>

#include<bits/stdc++.h>


using namespace std;

#define inf 0x3f3f3f3f


typedef long long ll;

typedef pair<int,int> P;


#define pi 3.141592653589793238


int mov[4][2]= {{-1,0},{0,1},{1,0},{0,-1}};




int Alice[1000000];

int Bob[1000000];



int main()

{

    freopen("C:/Users/86183/Desktop/input.txt","r",stdin);

    //freopen("‪C:\\Users\\86183\\Desktop\\output.txt","w",stdout);


    int k;

    string str;

    while(cin>>k){

        getchar();

        int Acnt=0;

        int Bcnt=0;

        getline(cin,str);

        int len=str.length();

        for(int i=0;i<len;i++){

            if(str[i]=='A'){

                if(i==0||!isalpha(str[i-1])){

                    if(i+5==len||(i+5<len&&!isalpha(str[i+5]))){

                        if(str[i+1]=='l'&&str[i+2]=='i'&&str[i+3]=='c'&&str[i+4]=='e'){

                            Alice[Acnt++]=i;

                            i+=4;

                        }

                    }

                }

            }else if(str[i]=='B'){

                if(i==0||!isalpha(str[i-1])){

                    if(i+3==len||(i+3<len&&!isalpha(str[i+3]))){

                        if(str[i+1]=='o'&&str[i+2]=='b'){

                            Bob[Bcnt++]=i;

                            i+=2;

                        }

                    }

                }

            }

        }

        ll ans=0;

        for(int i=0;i<Acnt;i++){

            int start=upper_bound(Bob,Bob+Bcnt,Alice[i]-k-4)-Bob;

            int End=upper_bound(Bob,Bob+Bcnt,Alice[i]+4+k+1)-Bob;

            if(start<Bcnt&&Bob[start]<=Alice[i]+4+k+1){

                ans+=End-start;

            }


            /*while(start<Bcnt&&Bob[start]<=Alice[i]+4+k+1){

                ans++;

                start++;

            }*/

        }

        printf("%lld\n",ans);

    }

    return 0;

}


 

0.0分

10 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区