hdu 5745(2016 Multi-University Training Contest 2)
来源:互联网 发布:淘宝商城鞋子男鞋冬季 编辑:程序博客网 时间:2024/06/07 05:07
La Vie en rose
Time Limit: 14000/7000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 528 Accepted Submission(s): 257
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 indicesi1,i2,...,ik such that 1≤i1<i2<...<ik<|p| and |ij−ij+1|>1 for all 1≤j<k .
2. swappij and pij+1 for all 1≤j≤k .
Now, for a given a strings=s1s2...sn , Professor Zhang wants to find all occurrences of all the generated patterns in s .
1. select some indices
2. swap
Now, for a given a string
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 integersn and m (1≤n≤105,1≤m≤min{5000,n}) -- the length of s and p .
The second line contains the strings and the third line contains the string p . Both the strings consist of only lowercase English letters.
The first line contains two integers
The second line contains the string
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
34 1abaca4 2aaaaaa9 3abcbacacbabc
Sample Output
10101110100100100
Author
zimpha
Source
2016 Multi-University Training Contest 2
题意:一个母串s,一个字串p,求p串是否能变成s的某一子串,p可以交换任意两个相邻字符,每个字符只能交换一次;最后得到一个二进制串,1表示s串从该位置为起始点,p变成与之一样;0反之。(据说比赛的时候好多人骂这题,说是条件1是可以挑两个字符交换......反正那句我没看懂,然后没管它....就那么AC了.....)
分析:我的想法是,先判断p和在s中对应的字串的某值(不知道怎么解释,因为是自己定义的.....)是否一样,不一样说明无论p怎么变都不可能变成s的那个字串,一样再继续,一位一位的判断,如果不一样就判断后一位是否和当前一样........总之也就是暴力一遍......
#include <iostream>#include <cstdio>#include <cstring>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <cmath>#include <algorithm>using namespace std;const double eps = 1e-6;const double pi = acos(-1.0);const int INF = 1e9;const int MOD = 1e9+7;#define ll long long#define CL(a,b) memset(a,b,sizeof(a))#define lson (i<<1)#define rson ((i<<1)|1)#define N 100010int n,m;int sum_s[N],sum_p[N];char s[N],p[5005];int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); scanf("%s%s",s+1,p+1); sum_s[0] = sum_p[0] = 0; for(int i=1; i<=n; i++) sum_s[i] = sum_s[i-1]+s[i]-'a'; for(int i=1; i<=m; i++) sum_p[i] = sum_p[i-1]+p[i]-'a'; bool flag; int pp = sum_p[m]; for(int i=m; i<=n; i++) { int ss = sum_s[i]-sum_s[i-m]; flag = true; if(ss == pp) { for(int j=i-m+1; j<=i; j++) { if(s[j] != p[m+j-i]) { if(j+1<=i&&s[j]==p[m+j-i+1]&&s[j+1]==p[m+j-i]) { j++; } else {flag = false; break;} } } } else flag = false; if(flag) printf("1"); else printf("0"); } for(int i=n-m+1; i<n; i++) printf("0"); printf("\n"); } return 0;}
0 0
- hdu 5745(2016 Multi-University Training Contest 2)
- hdu 5745 2016 Multi-University Training Contest 2 (暴力)
- 【HDU】5734 Acperience(2016 Multi-University Training Contest 2)
- hdu 5734 (2016 Multi-University Training Contest 2)
- hdu 5742 (2016 Multi-University Training Contest 2)
- hdu 5744(2016 Multi-University Training Contest 2)
- hdu 5745 La Vie en rose(2016 Multi-University Training Contest 2——暴力)
- 2016 Multi-University Training Contest 2 1001 hdu 5734 暴力
- HDU 2016 Multi-University Training Contest 2 1001
- HDU 5738 Eureka (from: 2016 Multi-University Training Contest 2)
- hdu 5734 Acperience 2016 Multi-University Training Contest 2
- 2016 Multi-University Training Contest 2-1005---HDU 5738 Eureka
- 2016 Multi-University Training Contest 2-1001---HDU 5734 Acperience
- hdu 5791 2016 Multi-University Training Contest 5(dp)
- HDU 5305 Friends(2015 Multi-University Training Contest 2)
- 2016 Multi-University Training Contest 2 Acperience
- 2016 Multi-University Training Contest 2
- 2016 Multi-University Training Contest 2 Acperience
- show processlist中kill锁表语句与慢sql
- Android Fragment嵌套使用存在的一些BUG以及解决方法
- validform表单验证插件最终版
- iOS状态栏效果 指示器 开源框架 附有Demo
- Unity3D的50个技巧:Unity3D最佳实践
- hdu 5745(2016 Multi-University Training Contest 2)
- 接收一个文件内容,通过读取开始和结束标志,分别将其内容保存到不同的文件中
- 【hdu 5738】Eureka
- HDU_01背包系列
- 大数据测试考题 - 纯技术交流(1)
- SecureCRT远程连接Linux(Ubuntu)
- android Ant 打包
- Android中页面自动刷新操作
- <30天自制操作系统>第四天