字典树。

插入的时候update一下节点出现的次数。

delete的时候,先把前缀之后的全删了。然后看前缀最后一个节点出现了几次,然后前缀上每个节点的次数都减去这个次数。

前缀从上到下再检查一遍,如果出现了次数为0的节点,也删去。

#include <stdio.h>
#include <math.h>
#include<cstring>
#include<cmath>
#include<map>
#include<string>
#include<algorithm>
using namespace std; struct Node
{
int val;
int f[];
} node[]; int root,n;
char op[], s[];
int tot; int newnode()
{
++tot;
node[tot].val=;
for(int i=; i<; i++) node[tot].f[i]=-;
return tot;
} void Insert()
{
int p=root;
for(int i=; s[i]; i++)
{
if(node[p].f[s[i]-'a']==-) node[p].f[s[i]-'a']=newnode();
p=node[p].f[s[i]-'a'];
node[p].val++;
}
} void Delete()
{
int p=;
bool Find=;
for(int i=; s[i]; i++)
{
if(node[p].f[s[i]-'a']==-)
{
Find=;
break;
}
p=node[p].f[s[i]-'a'];
}
if(Find==) return; for(int i=; i<; i++) node[p].f[i]=-; int Val=node[p].val; p=root;
for(int i=; s[i]; i++)
{
p=node[p].f[s[i]-'a'];
node[p].val=node[p].val-Val;
} p=;
for(int i=; s[i]; i++)
{
int tmp=node[p].f[s[i]-'a'];
if(node[tmp].val==)
{
node[p].f[s[i]-'a']=-;
break;
}
p=node[p].f[s[i]-'a'];
}
} void Search()
{
int p=root; bool flag=;
for(int i=; s[i]; i++)
{
if(node[p].f[s[i]-'a']==-)
{
flag=;
break;
}
p=node[p].f[s[i]-'a'];
} if(flag) printf("No\n");
else printf("Yes\n");
} int main()
{
while(~scanf("%d",&n))
{
tot=; root=;
for(int i=; i<; i++) node[root].f[i]=-;
for(int i=; i<=n; i++)
{
scanf("%s%s",op,s);
if(strcmp(op,"insert")==) Insert();
else if(strcmp(op,"delete")==) Delete();
else if(strcmp(op,"search")==) Search();
}
}
return ;
}

2016"百度之星" - 资格赛(Astar Round1) Problem C的更多相关文章

  1. HDU 5688:2016"百度之星" - 资格赛 Problem D

    原文链接:https://www.dreamwings.cn/hdu5688/2650.html Problem D Time Limit: 2000/1000 MS (Java/Others)    ...

  2. HDU 5686:2016"百度之星" - 资格赛 Problem B

    原文链接:https://www.dreamwings.cn/hdu5686/2645.html Problem B Time Limit: 2000/1000 MS (Java/Others)    ...

  3. HDU 5685:2016"百度之星" - 资格赛 Problem A

    原文链接:https://www.dreamwings.cn/hdu5685/2637.html Problem A Time Limit: 2000/1000 MS (Java/Others)    ...

  4. 2016百度之星 资格赛ABCDE

    看题:http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=690 交题:http://acm.hdu.edu.cn/search.php ...

  5. 2016"百度之星" - 资格赛(Astar Round1) Problem E

    简单模拟题,耐心写就能过. #include <stdio.h> #include <math.h> #include<cstring> #include<c ...

  6. 2016"百度之星" - 资格赛(Astar Round1) Problem D

    排个序,map直接搞. #include <stdio.h> #include <math.h> #include<cstring> #include<cma ...

  7. 2016"百度之星" - 资格赛(Astar Round1) Problem B

    规律题,斐波那契数列,数据有毒,0的时候输出换行.会爆longlong,写个大数模板或者Java搞. import java.io.BufferedInputStream; import java.m ...

  8. 2016"百度之星" - 资格赛(Astar Round1) Problem A

    保存前缀乘,询问的时候输出c[ri]/c[li-1]即可,因为是除法,所以计算一下c[li-1]的逆元. #include <stdio.h> #include <math.h> ...

  9. 2016"百度之星" - 资格赛(Astar Round1)

    逆元 1001 Problem A 求前缀哈希和逆元 #include <bits/stdc++.h> typedef long long ll; const int MOD = 9973 ...

随机推荐

  1. shell之路【第一篇】shell简介与入门

    shell简介 1.Shell 诞生于 Unix,Unix的第一个脚本语言,是与 Unix/Linux 交互的工具,单独地学习 Shell 是没有意义的,shell使用的熟练程度反映了用户对Unix/ ...

  2. JSP基本语法--包含指令<%@include file="路径"%> <jsp:include page>

    包含指令,真正改变的地方只有具体内容处: 方法1: 在每个jsp页面(HTML)都包含工具栏,头部信息,尾部信息,具体内容 方法2: 将工具栏,头部信息,尾部信息都分成各个独立的文件,使用的时候直接导 ...

  3. windows指令

    &        无条件执行&符号后面的命令: &&      当&&前面的命令成功执行时,执行&&后面的命令,否则不执行: ||   ...

  4. asp之vbscript函数

    '函数Abs(number)'返回绝对值.Array(arglist)'创建一个数组.Asc(string)'返回字符串第一个字符的ANSI码.Atn(number)'返回反正弦值.CBool(exp ...

  5. ubuntu apt-get update 连接不到指定的源

    问题描述: ubuntu apt-get update 连接不到指定的源,修改了几个软件源还是连接不上,同样的软件源在别的机器上都可以正常使用,后来发现每次 sudo apt-get update操作 ...

  6. 学习笔记:GLSL Core Tutorial – Pipeline (OpenGL 3.2 – OpenGL 4.2)

    GLSL Core Tutorial – Pipeline (OpenGL 3.2 – OpenGL 4.2) GLSL 是一种管道,一种图形化的流水线 1.GLSL 的具体工作流程: 简化流程如下: ...

  7. iframe子页面调用父页面javascript函数的方法

    1.iframe子页面调用 父页面js函数 子页面调用父页面函数只需要写上window.parent就可以了.比如调用a()函数,就写成: window.parent.a(); 2.iframe父页面 ...

  8. Learning Java characteristics (Java in a Nutshell 6th)

    Java characteristics: Java .class files are machine-independent, including the endianness. Java .cla ...

  9. awstats + tomcat + windows

    下载: 1.apache-tomcat-7.0.67 2.ActivePerl-5.22.1.2201-MSWin32-x86-64int-299574.msi 3.awstats-7.4.zip 修 ...

  10. 用for while 成绩的有效输入

    #include "stdio.h" void main() { int score,s; printf("请输入你的成绩:"); scanf("%d ...