HDU 5687 字典树入门
Problem C
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1423 Accepted Submission(s): 426
1、insert : 往神奇字典中插入一个单词
2、delete: 在神奇字典中删除所有前缀等于给定字符串的单词
3、search: 查询是否在神奇字典中有一个字符串的前缀等于给定的字符串
insert hello
insert hehe
search h
delete he
search hello
No
#include<bits/stdc++.h>
using namespace std;
struct node
{
int have;
node *child[];
node(){have=;for(int i=;i<;++i) child[i]=NULL;}
};
node *root;
void release(node *p)
{
if(p==NULL) return;
for(int i=;i<;++i){
if(p->child[i]!=NULL) release(p->child[i]);
}
delete p;
}
void Insert(char *s)
{
node *p=root;
int n1=strlen(s);
for(int i=;i<n1;++i){int t=s[i]-'a';
if(p->child[t]==NULL)
p->child[t]=new node();
p=p->child[t];
p->have++;
}
} void Delete(char *s)
{ node *p=root,*pre=p;
int n1=strlen(s),t,num=;
for(int i=;i<n1;++i){ t=s[i]-'a';
if(p->child[t]==NULL) return;
pre=p;
p=p->child[t];
}num=p->have;
release(p);
pre->child[t]=NULL;
p=root;
for(int i=;i<n1-;++i){
p=p->child[s[i]-'a'];
p->have-=num;
}
}
bool Search(char *s)
{
node *p=root;
int n1=strlen(s);
for(int i=;i<n1;++i){
int t=s[i]-'a';
if(p->child[t]==NULL) return ;
p=p->child[t];
}
if((p->have)<) return ;
return ;
}
int main()
{
int N,i,j;
char s1[],s2[];
cin>>N;
root=new node();
while(N--){
scanf("%s%s",s1,s2);
if(!strcmp(s1,"insert")){
Insert(s2) ;
}
else if(!strcmp(s1,"delete")){
Delete(s2);
}
else if(!strcmp(s1,"search")){
Search(s2)?puts("Yes"):puts("No");
}
}release(root);
return ;
}
HDU 5687 字典树入门的更多相关文章
- HDU 5687 字典树插入查找删除
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include< ...
- hdu 1247 (字典树入门)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDU 4825 Xor Sum(01字典树入门题)
http://acm.hdu.edu.cn/showproblem.php?pid=4825 题意: 给出一些数,然后给出多个询问,每个询问要从之前给出的数中选择异或起来后值最大的数. 思路:将给出的 ...
- HDU 1251 统计难题(字典树入门模板题 很重要)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU 5384 字典树、AC自动机
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5384 用字典树.AC自动机两种做法都可以做 #include<stdio.h> #includ ...
- hdu 2112(字典树+最短路)
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 2072(字典树模板,set,map均可做)
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...
- Chip Factory HDU - 5536 字典树(删除节点|增加节点)
题意: t组样例,对于每一组样例第一行输入一个n,下面在输入n个数 你需要从这n个数里面找出来三个数(设为x,y,z),找出来(x+y)^z(同样也可以(y+z)^1)的最大值 ("^&qu ...
随机推荐
- 20165324 Java实验四 Android程序设计
20165324 Java实验四 Android程序设计 一.实验报告封面 课程:Java程序设计 班级:1653班 姓名:何春江 学号:20165324 指导教师:娄嘉鹏 实验日期:2018年5月1 ...
- 前端须知的http header
文件信息: Content-Type: application/x-javascript Content-Length: 2000 Content-Type:指定请求和响应的内容类型,如果未指定即为t ...
- sqlserver 2005/2008 导入超大sql文件
SQLCMD -E -dmaster -ic:\Scripts\create_db.sql 安装了Microsoft® SQL Server® 2008 R2 Native Client可用
- Using RUNDLL32.exe to call a function within a dll
Using RUNDLL32.exe to call a function within a dll Rundll32 is a utility included with Window ...
- JS:parseInt("08")或parseInt("09")转换返回0的原因
一.parseInt用法 parseInt(s); parseInt(s,radix) 二.第一个方式不再多说,第二个方式,radix是s所基于的进制.范围为2-36(不在此范围函数将返回NaN). ...
- django之路由(url)
前言: Django大致工作流程 1.客户端发送请求(get/post)经过web服务器.Django中间件. 到达路由分配系统 2.路由分配系统根据提取 request中携带的的url路径(path ...
- wait、notify为什么要放在同步代码块中
等待方遵循的原则: 获取对象的锁,不满足条件就调用wait()方法,条件满足继续执行 通知方原则: 获取对象的锁,改变条件,然后notify 每个对象都有一个监视器锁,这个监视器锁的数据结构如下: w ...
- Ubuntu16.04中用et对jmeter生成的数据统计成图表
在Ubuntu系统中,用ctrl+Alt+t 打开终端: 输入et,即打开wps: 整理需要形成图表的数据,如: 用excel生成图表,如下: 表得出的性能图表,方法: 1.工具栏中选择插入——二维折 ...
- Python 实例2—购物车
老男孩教学学习笔记 """启动程序后,让用户输入工资,然后打印商品列表允许用户根据商品编号购买商品用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒可随机退出,退出 ...
- 自定义圆形头像CircleImageView的使用和源码分析
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0806/3268.html tools:context="com.ex ...