RE………………
  • 板块灌水区
  • 楼主idgg007
  • 当前回复3
  • 已保存回复3
  • 发布时间2021/11/13 17:38
  • 上次更新2023/11/4 00:41:59
查看原帖
RE………………
297831
idgg007楼主2021/11/13 17:38

poj2752 IyPs58.jpg

#include<string>
#include<queue>
#include<vector>
#include<iostream>
struct Tire {
	int son[26];
	int fail;
};
std::queue<int>que;
std::vector<Tire>tire;
std::string getin;
int lenth;
void BuildTireTree(int n, int k) {
	if (k == lenth) {
		return;
	}
	tire[n].son[getin[k] - 'a'] = n + 1;
	tire.push_back(Tire{0});
	BuildTireTree(n + 1, k + 1);
}
void IniFail() {
	que.push(1);
	for (int i = 0; i < 26; i++) {
		tire[0].son[i] = 1;
	}
	tire[0].fail = 1;
	while (!que.empty()) {
		int head = que.front();
		for (int i = 0; i < 26; i++) {
			if (tire[head].son[i]) {
				tire[tire[head].son[i]].fail = tire[tire[head].fail].son[i];
				que.push(tire[head].son[i]);
			} else {
				tire[head].son[i] = tire[tire[head].fail].son[i];
			}
		}
		que.pop();
	}
}
void Find(int n) {
	if (tire[n].fail != 0) {
		Find(tire[n].fail);
		std::cout << n - 1 << " ";
	}
}
int main() {
	while (std::cin >> getin) {
		tire.clear();
		lenth = getin.size();
		tire.push_back(Tire{0});
		tire.push_back(Tire{0});
		BuildTireTree(1, 0);
		IniFail();
		Find(lenth + 1);
		std::cout<<"\n";
	}
	return 0;
}

what happened??WDF??

2021/11/13 17:38
加载中...