• 2017 计蒜之道 初赛 第一场 B.阿里天池的新任务


    该文被密码保护

        

      

              

      

    2017 计蒜之道 初赛 第一场 B.阿里天池的新任务

      

     1 /* QYP kuai wo dai ma*/
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<iomanip>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<ctime>
    10 #include<cmath>
    11 #include<stack>
    12 #include<map>
    13 #include<set>
    14 #define rep(i,a,b) for(register int i=a;i<=b;i++)
    15 #define ll long long
    16 #define re register
    17 using namespace std;
    18 const int N=1e6;
    19 int w[N+10];
    20 int n,a,b,L,R;
    21 char s[N+10],t[N+10];
    22 int nxt[N+10];
    23 inline int gi() {
    24     re int res=0;
    25     char ch=getchar();
    26     while(ch<'0'||ch>'9') ch=getchar();
    27     while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar();
    28     return res;
    29 }
    30 void get_w() {
    31     w[1]=b;
    32     for(re int i=2;i<=n;i++) w[i]=(w[i-1]+a)%n;
    33 }
    34 void get_s() {
    35     for(re int i=1;i<=n;i++) {
    36         if(w[i]>=L&&w[i]<=R) {
    37             if(w[i]%2==0) s[i]='A';
    38             else s[i]='T';
    39         }
    40         else {
    41             if(w[i]%2==0) s[i]='G';
    42             else s[i]='C';
    43         }
    44     }
    45 }
    46 void NEXT() {
    47     int len=strlen(t+1);
    48     nxt[1]=0;
    49     int j=0;
    50     for(re int i=2;i<=len;i++) {
    51         while(j&&t[j+1]!=t[i]) j=nxt[j];
    52         if(t[j+1]==t[i]) nxt[i]=++j;
    53     }
    54 }
    55 void KMP() {
    56     int lens=strlen(s+1),j=0;
    57     int lent=strlen(t+1);
    58     int ans=0;
    59     for(re int i=1;i<=lens;++i) {
    60         while(j&&t[j+1]!=s[i]) j=nxt[j];
    61         if(t[j+1]==s[i]) ++j;
    62         if(j==lent) {ans++;j=nxt[j];}
    63     }
    64     cout<<ans;
    65 }
    66 int main() {
    67     freopen("2.in","r",stdin);
    68     freopen("2.out","w",stdout);
    69     n=gi(),a=gi(),b=gi(),L=gi(),R=gi();
    70     s[0]='@',t[0]='$';
    71     scanf("%s",t+1);
    72     get_w();
    73     get_s();
    74     NEXT();
    75     KMP();
    76     return 0;
    77 }
  • 相关阅读:
    PHP数组函数
    sublime常用快捷键
    PHP中array_merge函数与array+array的区别
    【转】2017PHP程序员的进阶之路
    phpmyadmin上传sql文件大小限制问题解决方案
    二. python的os模块
    一. python的collections模块
    一. python进阶(文件的读写编码)
    七. python进阶(内置函数和高阶函数)
    六. python进阶(递归)
  • 原文地址:https://www.cnblogs.com/ypz999/p/6883175.html
Copyright © 2020-2023  润新知