2016百度之星资格赛 C题
来源:互联网 发布:mac steam 游戏存档 编辑:程序博客网 时间:2024/05/22 00:30
Problem C
Accepts: 726
Submissions: 5985
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
YesNo字典树,删除有点麻烦#include <iostream>#include <cstring>#include <cstdio>using namespace std;struct trie{ int v; trie *ch[35];};trie *root;char c[50],s[50];int n;void buildtrie(char *s){ int l=strlen(s); trie *p=root,*q=NULL; for (int i=0;i<l;i++) { int t=s[i]-'a'; if (p->ch[t]!=NULL) { p=p->ch[t]; p->v++; } else { q=new trie; q->v=1; for (int j=0;j<35;j++) q->ch[j]=NULL; p->ch[t]=q; p=p->ch[t]; } }}void del(char *s){ trie *p=root,*path[50]; int h=0,v; for (int i=0;i<50;i++) path[i]=NULL; int l=strlen(s); for (int i=0;i<l;i++) { int t=s[i]-'a'; if (p->ch[t]==NULL) return ; p=p->ch[t]; path[h++]=p; } v=p->v; for (int i=0;i<35;i++) p->ch[i]=NULL; for (int i=0;i<h;i++) path[i]->v-=v;}bool ser(char *s){ trie *p=root; int l=strlen(s); for (int i=0;i<l;i++) { int t=s[i]-'a'; if (p->ch[t]) { p=p->ch[t]; if (p->v==0) return 0; } else return 0; } return 1;}int main(){ root=new trie; root->v=0; for (int i=0;i<35;i++) root->ch[i]=NULL; scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%s%s",c,s); if (c[0]=='i') buildtrie(s); else if (c[0]=='d') del(s); else { if (ser(s)) printf("Yes\n"); else printf("No\n"); } } return 0;}
0 0
- 2016百度之星资格赛 C题
- 2016"百度之星" - 资格赛 Problem C
- 2016百度之星资格赛C
- 百度之星 2016资格赛 Problem C
- 2016百度之星资格赛E题
- 2016百度之星资格赛 A题
- 2016百度之星资格赛 B题
- 2016百度之星资格赛 D题
- 2016百度之星资格赛 E题
- 2016百度之星资格赛D题
- 2016百度之星资格赛 B题
- 百度之星2016 资格赛D题
- 2016 百度之星 资格赛
- 2016百度之星资格赛
- 2016百度之星资格赛
- 2016百度之星资格赛
- 2016百度之星资格赛
- 2016"百度之星" - 资格赛
- 关于“Error: "const char *" 类型的实参与 "LPCWSTR"类型的形参不兼容”错误的解决方案
- Android中各种奇葩,难解的Json
- C++虚基类的内存布局(上)
- 飞思卡尔高级驾驶员辅助系统(ADAS)解决方案
- 学习归幷排序
- 2016百度之星资格赛 C题
- 设置ssh免登录并设置别名
- MapReduce 之 倒排索引 基本概念、设计思路和源码分析
- XueXX and Chessboard(中南OJ)
- 单例类
- Leetcode 238. Product of Array Except Self
- 实现开关按钮
- 新项目如何选择合适电源模块
- 2016"百度之星" - 资格赛(Astar Round1)Problem A B C D--java代码