2016"百度之星" - 资格赛 Problem C
来源:互联网 发布:ping命令使用的端口 编辑:程序博客网 时间:2024/05/22 15:31
解题思路:裸tire,没什么好说的。
/* ***********************************************┆ ┏┓ ┏┓ ┆┆┏┛┻━━━┛┻┓ ┆┆┃ ┃ ┆┆┃ ━ ┃ ┆┆┃ ┳┛ ┗┳ ┃ ┆┆┃ ┃ ┆┆┃ ┻ ┃ ┆┆┗━┓ 马 ┏━┛ ┆┆ ┃ 勒 ┃ ┆ ┆ ┃ 戈 ┗━━━┓ ┆┆ ┃ 壁 ┣┓┆┆ ┃ 的草泥马 ┏┛┆┆ ┗┓┓┏━┳┓┏┛ ┆┆ ┃┫┫ ┃┫┫ ┆┆ ┗┻┛ ┗┻┛ ┆************************************************ */#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>using namespace std;#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)const int inf_int = 2e9;const long long inf_ll = 2e18;#define mod 1000000007#define ll long long#define ull unsigned long longstruct tire{ tire *word[26]; int cnt; tire() { cnt=0; for(int i=0;i<26;i++) word[i]=NULL; }};void build(tire *rt,char *str){ int i; for(i=0;str[i]!='\0';i++) { if(!rt->word[str[i]-'a']) { rt->word[str[i]-'a']=new tire(); } rt->word[str[i]-'a']->cnt++; rt=rt->word[str[i]-'a']; }}bool findtire(tire *rt,char *str){ int i; for(i=0;str[i]!='\0';i++) { if(rt->word[str[i]-'a']) rt=rt->word[str[i]-'a']; else break; } if(str[i]=='\0') { if(rt->cnt>0) return true; } return false;}void del(tire *rt,char *str){ tire *head,*tail; head=rt; int num,i; for(i=0;str[i]!='\0';i++) { if(rt->word[str[i]-'a']) { tail=rt; num=rt->word[str[i]-'a']->cnt; rt=rt->word[str[i]-'a']; } else break; } if(str[i]=='\0') { free(tail->word[str[i-1]-'a']); tail->word[str[i-1]-'a']=NULL; for(int j=0;str[j]!='\0';j++) { if(head->word[str[j]-'a']!=NULL) { head->word[str[j]-'a']->cnt-=num; head=head->word[str[j]-'a']; } } }}int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); tire *rt=new tire();int n;scanf("%d",&n);while(n--) { char s[35],order[10]; scanf("%s %s",order,s); if(order[0]=='i') { build(rt,s); } else if(order[0]=='d') { del(rt,s); } else { if(findtire(rt,s)) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } return 0;}
0 0
- 2016"百度之星" - 资格赛 Problem C
- 百度之星 2016资格赛 Problem C
- 2016"百度之星" - 资格赛(Astar Round1)Problem C
- 2016"百度之星" - 资格赛(Astar Round1)Problem C
- 2016"百度之星" - 资格赛 Problem C 字典树
- 2016百度之星 资格赛 1003 Problem C 容器瞎搞
- 2016-百度之星-资格赛-Problem C【字典树】
- 2016 百度之星资格赛 Problem C (Trie模板)
- HDU-5687 Problem C(2016"百度之星"-资格赛)
- 2016百度之星资格赛 Problem B
- 2016"百度之星" - 资格赛 Problem A
- 2016"百度之星" - 资格赛 Problem D
- 2016"百度之星" - 资格赛 Problem B
- 2016"百度之星" - 资格赛 Problem D
- 2016-百度之星-资格赛-Problem D
- 百度之星 2016资格赛 Problem A
- 2016百度之星资格赛 Problem A
- HDU 5687 Problem C (2016年百度之星资格赛C题)
- Android Studio使用Lint进行代码检查
- ora-01950:对表空间XXX无权限
- 第十一周【项目3- 警察和厨师2】
- Android Lint官方静态代码检查工具
- IMF SparkStreaming 自定义EventLoop 从入门到放弃
- 2016"百度之星" - 资格赛 Problem C
- ORA-12514 startup mount时遇到ORA-12514
- 周赛题(2016"百度之星" - 资格赛(Astar Round1))
- 通过CIFilter生成二维码
- 2016"百(sha)度(bi)之星"-资格赛(Astar Round 1)题解
- 如何下载Instagram照片/视频到手机
- php以图搜图
- iOS 打包问题汇总
- mysql connector c++ {realStr=<读取字符串的字符时出错。> }