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 1≤i1<i2<...<ik<|p| and |ij−ij+1|>1 for all 1≤j<k .
2. swap pij and pij+1 for all 1≤j≤k .

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 (1≤n≤105,1≤m≤min{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+m−1 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。
 
纯暴力,从第一个字符开始比较就好。
 
附上代码:
 
 #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define ll long long
using namespace std;
char s1[],s2[];
int main()
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
int len1,len2;
memset(s1,'\0',sizeof(s1));
memset(s2,'\0',sizeof(s2));
scanf("%d%d",&len1,&len2);
scanf("%s%s",s1,s2);
char w;
if(len1<len2)
{
for(i=; i<len1; i++)
printf("");
printf("\n");
continue;
}
for(i=; i<len1; i++)
{
int t=;
for(j=i; j<i+len2&&j<len1; j++)
{
if(s1[j]!=s2[t])
{
if(j==i+len2-)
break;
if(s1[j+]!=s2[t]||s1[j]!=s2[t+])
break;
else
{
t+=;
j+=;
}
}
else
{
t++;
}
}
if(j==i+len2)
printf("");
else
printf(""); }
printf("\n");
}
return ;
}

最新文章

  1. ASP.NET Core 中文文档 第三章 原理(14)服务器
  2. 计划任务,机器码与注册码,Web服务
  3. 网站对话框开源脚本--ArtDialog V6.0
  4. OMG 在线思维导图都有开源的
  5. Xdebug开源PHP程序调试器
  6. 在win7上建立本地FTP站点详细步骤
  7. RTB日志分析MR程序设计
  8. Android(java)学习笔记184:生成 4种 不同权限的文件
  9. sid超过8个字符处理步骤
  10. js删除选中的复选框中的父辈。
  11. org.hibernate.service.jndi.JndiException: Error parsing JNDI name []
  12. 4个常用的HTTP安全头部
  13. 如何debug ruby
  14. flex 4 datagrid 奇偶行颜色设置
  15. STM32开发指南-蜂鸣器实验
  16. 5、python的变量和常量
  17. CF 468B Two Sets
  18. Spark 论文篇-RDD:一种为内存化集群计算设计的容错抽象(中英双语)
  19. MRPT编译
  20. ideal通过svn上传项目和激活方式

热门文章

  1. 2019-9-2-win10-uwp-存放网络图片到本地
  2. 【P1203】 【USACO1.1】坏掉的项链Broken Necklace
  3. Python使用Pandas高效处理测试数据
  4. CentOS上搭建Yii2 --2017
  5. Java ANSI转码UTF-8
  6. SQLServer → 09:索引
  7. rqnoj86 智捅马蜂窝
  8. thinkphp php审核后返回信息给html
  9. Hdu 4493
  10. Python里的堆heapq