HDOJ 2087 剪花布條

2021-06-29 13:59:28 字數 1984 閱讀 2299

題意:給出主串與模式串,找出主串中不重疊的模式串的個數

思路:kmp,每找到一組匹配時,改變起點位置即可

注意點:無

以下為ac**:

run id

submit time

judge status

pro.id

exe.time

exe.memory

code len.

language

author

13038007

2015-03-05 23:14:23

accepted

2087

0ms1192k

2294 b

g++luminous11

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include //#include #define ll long long

#define ull unsigned long long

#define all(x) (x).begin(), (x).end()

#define clr(a, v) memset( a , v , sizeof(a) )

#define pb push_back

#define rdi(a) scanf ( "%d", &a )

#define rdii(a, b) scanf ( "%d%d", &a, &b )

#define rdiii(a, b, c) scanf ( "%d%d%d", &a, &b, &c )

#define rs(s) scanf ( "%s", s )

#define pil(a) printf ( "%d\n", a )

#define piil(a,b) printf ( "%d %d\n", a, b )

#define piil(a,b,c) printf ( "%d %d %d\n", a, b, c )

#define psl(s) printf ( "%s\n", s )

#define rep(i,m,n) for ( int i = m; i <= n; i ++ )

#define dep(i,m,n) for ( int i = m; i >= n; i -- )

#define repi(i,m,n,k) for ( int i = m; i <= n; i += k )

#define depi(i,m,n,k) for ( int i = m; i >= n; i -= k )

#define read(f) freopen(f, "r", stdin)

#define write(f) freopen(f, "w", stdout)

using namespace std;

const double pi = acos(-1);

const double eps = 1e-10;

const int dir[4][2] = ;

struct node

node( int _x, int _y ) : x(_x), y(_y) {}

node( int _x, int _y, int _cnt ) : x(_x), y(_y), cnt(_cnt) {}

};int pre[10000];

char x[1005];

char y[1005];

void prekmp ( int m )

}int kmp ( int m, int n )

}return ans;

}int main()

return 0;

}

剪花布條 HDOJ2087

題目鏈結 解題思路 這是kmp演算法模板的應用。需要注意的地方就是,這裡的子串需要重新取,所以對於j的處理時要改變一下。include include include const int maxn 1010 int next maxn char str maxn pat maxn void getn...

HDOJ2087 剪花布條(KMP)

problem solution 模板題,沒啥好說的。kmp匹配 如果成功,就把j 0,從頭開始匹配,答案累加。codes include include include using namespace std const int maxn 1010 char a maxn b maxn int n...

hdu 2087 剪花布條

include include includeusing namespace std const int maxn 1004 char str maxn str1 maxn int main printf d n count return 0 此題主要是strstr 函式的應用!據說也可以用kmp來...