题意:每次询问:输出当前自库中以之为前缀的字符串频率最大的(相等时字典序最小)的字符串。此题开始就跪,字典树不是问题,关键是解决每次输出就是把这个串在字典树跑了一遍之后(停在某节点node),输出以node为根节点的子树中的权值最大的“终止节点”,这个问题,开始走w[u]最大的,发现不行啊(反例很多),后来发现,给每个结点加一个状态,记录以它为根的子树中,权最大的串,(当然还有权值),,每插入一个串后,w[u]更新(u为终止结点),跟新每个结点的属性即可。#include #include #include #include #include #include using namespace std;int tree[310000][27]; //字典树struct node //结点属性{ int maxchild; string cs;};node nodes[310000];int w[310100]; int numv=0; //点数int n;void insert(string s) //插入s{ queue q; //再走一遍更新之用。 int u=0; int len=s.size(); for(int i=0;i s) nodes[cur].cs=s; } }}string find(string s) //查找{ int u=0; int len=s.size(); for(int i=0;i