zoukankan      html  css  js  c++  java
  • hdu 5745 La Vie en rose(2016多校第二场)

    La Vie en rose

    Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 643    Accepted Submission(s): 328


    Problem Description
    Professor Zhang would like to solve the multiple pattern matching problem, but he only has only one pattern string p=p1p2...pm . So, he wants to generate as many as possible pattern strings from p using the following method:

    1. select some indices i1,i2,...,ik such that 1i1<i2<...<ik<|p| and |ijij+1|>1 for all 1j<k .
    2. swap pij and pij+1 for all 1jk .

    Now, for a given a string s=s1s2...sn , Professor Zhang wants to find all occurrences of all the generated patterns in s .
     
    Input
    There are multiple test cases. The first line of input contains an integer T , indicating the number of test cases. For each test case:

    The first line contains two integers n and m (1n105,1mmin{5000,n}) -- the length of s and p .

    The second line contains the string s and the third line contains the string p . Both the strings consist of only lowercase English letters.
     
    Output
    For each test case, output a binary string of length n . The i -th character is "1" if and only if the substring sisi+1...si+m1 is one of the generated patterns.
     
    Sample Input
    3
    4 1
    abac
    a
    4 2
    aaaa
    aa
    9 3
    abcbacacb
    abc
     
    Sample Output
    1010
    1110
    100100100
     
    Author
    zimpha
     
    题意:输入两个字符串s串和p串,p串从s串的第一个字符开始一直比较到最后一个(如果后面字符比p串段,则肯定输出0),比较的时候若不相同,则p串的字符可以相邻交换进行比较,每个位置只能交换一次,(只是当前比较的交换,而不是永久交换),相同字符串输出1,不同则输出0。
     
    纯暴力,从第一个字符开始比较就好。
     
    附上代码:
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <cstring>
     5 #define  ll long long
     6 using namespace std;
     7 char s1[110005],s2[5005];
     8 int main()
     9 {
    10     int T,i,j;
    11     scanf("%d",&T);
    12     while(T--)
    13     {
    14         int len1,len2;
    15         memset(s1,'',sizeof(s1));
    16         memset(s2,'',sizeof(s2));
    17         scanf("%d%d",&len1,&len2);
    18         scanf("%s%s",s1,s2);
    19         char w;
    20         if(len1<len2)
    21         {
    22             for(i=0; i<len1; i++)
    23                 printf("0");
    24             printf("
    ");
    25             continue;
    26         }
    27         for(i=0; i<len1; i++)
    28         {
    29             int t=0;
    30             for(j=i; j<i+len2&&j<len1; j++)
    31             {
    32                 if(s1[j]!=s2[t])
    33                 {
    34                     if(j==i+len2-1)
    35                         break;
    36                         if(s1[j+1]!=s2[t]||s1[j]!=s2[t+1])
    37                             break;
    38                         else
    39                         {
    40                             t+=2;
    41                             j+=1;
    42                         }
    43                 }
    44                 else
    45                 {
    46                     t++;
    47                 }
    48             }
    49             if(j==i+len2)
    50                 printf("1");
    51             else
    52                 printf("0");
    53 
    54         }
    55         printf("
    ");
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    The first appliaction for "Hello World!"
    zone
    learn to study
    深入理解 Angular 2 变化监测和 ngZone
    看看吧
    生命周期钩子
    一个简单的todo
    依赖注入
    @Output()
    @Input
  • 原文地址:https://www.cnblogs.com/pshw/p/5695332.html
Copyright © 2011-2022 走看看