HDU 5745 La Vie en rose
La Vie en rose
Time Limit: 14000/7000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 744 Accepted Submission(s): 386
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.
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.
#include <bits/stdc++.h> char s[100005];
char p[5005]; int main()
{
int T, n, m;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &m);
scanf("%s%s", s, p);
for(int i = 0; i < n; ++i){
if(i>n-m){
putchar('0');
continue;
}
bool f = true;
for(int j = 0; j < m; ){
if(j<m-1 && p[j] == s[i+j+1] && p[j+1] == s[i+j]){
j += 2;
continue;
}
else if(p[j] != s[i+j]){
f = false;
break;
}
++j;
}
putchar(f ? '1' : '0');
}
puts("");
}
return 0;
}
HDU 5745 La Vie en rose的更多相关文章
- HDU 5745 La Vie en rose 暴力
La Vie en rose 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5745 Description Professor Zhang woul ...
- 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)T ...
- hdu 5745 La Vie en rose DP + bitset优化
http://acm.hdu.edu.cn/showproblem.php?pid=5745 这题好劲爆啊.dp容易想,但是要bitset优化,就想不到了. 先放一个tle的dp.复杂度O(n * m ...
- HDU 5745 La Vie en rose (DP||模拟) 2016杭电多校联合第二场
题目:传送门. 这是一道阅读理解题,正解是DP,实际上模拟就能做.pij+1 指的是 (pij)+1不是 pi(j+1),判断能否交换输出即可. #include <iostream> # ...
- hdu5745 La Vie en rose 巧妙地dp+bitset优化+滚动数组减少内存
/** 题目:hdu5745 La Vie en rose 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5745 题意:题目给出的变换规则其实就是交换相邻 ...
- La Vie en rose (模拟)
#include<bits/stdc++.h> using namespace std; ; ; int T, n, m; char str1[maxm], str2[maxn]; int ...
- hdu5745--La Vie en rose (DP+bitset)
好题,学到新姿势! 题意:给两个字符串 a 和 b ,b可以进行变换,规则是可以任意交换相邻两个字符的位置,但是不可以有交叉(例如3和4交换,5和6交换 互不影响,但是2和3,3和4就不可以).求a中 ...
- HDU5745-La Vie en rose-字符串dp+bitset优化
这题现场的数据出水了,暴力就能搞过. 标解是拿bitset做,转移的时候用bitset优化过的操作(与或非移位)来搞,复杂度O(N*M/w) w是字长 第一份标程的思路很清晰,然而后来会T. /*-- ...
- 2016 Multi-University Training Contest 2题解报告
A - Acperience HDU - 5734 题意: 给你一个加权向量,需要我们找到一个二进制向量和一个比例因子α,使得|W-αB|的平方最小,而B的取值为+1,-1,我们首先可以想到α为输入数 ...
随机推荐
- POJ 3277 City Horizon(叶子节点为[a,a+1)的线段树+离散化)
网上还有用unique函数和lowerbound函数离散的方法,可以百度搜下题解就有. 这里给出介绍unique函数的链接:http://www.cnblogs.com/zhangshu/archiv ...
- 2013 ACM-ICPC长沙赛区全国邀请赛—Special equations
……但是没仔细看,直接跳过了 这题直接枚举就可以过了 ;}
- lintcode : find peak element 寻找峰值
题目 寻找峰值 你给出一个整数数组(size为n),其具有以下特点: 相邻位置的数字是不同的 A[0] < A[1] 并且 A[n - 2] > A[n - 1] 假定P是峰值的位置则满足 ...
- C++中全局变量的那些事儿
C/C++中的变量分为全局变量.静态全局变量.局部变量和静态局部变量,在<C/C++中静态局部变量的特点与应用>中我们介绍过静态局部变量,今天我们的目标是全局变量. 单个文件中的全局变量 ...
- Generic repository pattern and Unit of work with Entity framework
原文 Generic repository pattern and Unit of work with Entity framework Repository pattern is an abstra ...
- Qt出现警告 Unescaped backslashes are deprecated!解决办法
Fixing Qt Warning: Unescaped backslashes are deprecated! From: http://www.openguru.com/2011/10/fixin ...
- Hibernate开发之二 映射主键-
<class name="cn.itcast.e_hbm_id.User" table="user"> <!-- 映射主 ...
- Struts2+JSON+JQUERY DEMO
看到别人用了Struts2和JSON,自己也想练练手.记录下练习过程中遇到的问题,以便参考. 使用Maven新建项目: 先挂上pom.xml <project xmlns="http: ...
- sed替换单引号
echo "Cfoo'barxml" | sed "s/'/::/g" | sed 's/::/\\:/g' | sed "s/:/'/g&quo ...
- 使用设置报头x-Frame-Options限制iframe网页嵌套
x-frame-options的出现一部分是为了防止一些别有用心的者制作钓鱼网站,现在支持的浏览器有一下: chrome 4.1.249.1042 firefox 3.6.9(1.9.2.9) IE ...