HDU 1057 What Are You Talking About trie树 简单
http://acm.hdu.edu.cn/showproblem.php?pid=1075
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=;
const double eps=1e-;
const long long modn=;
struct tri{
bool exist;
int next[];
char ch[];
}e[maxn*];
int tot=;
char a[]={},b[]={},cc;
char st[]={'S','T','A','R','T'};
char ed[]={'E','N','D'};
void doit(int x,int k,int j){
if(k<j){
e[x].exist=;
strcpy(e[x].ch,b);
return;
}
int z=a[j]-'a';
if(e[x].next[z]){
doit(e[x].next[z],k,j+);
}else{
e[x].next[z]=++tot;
doit(tot,k,j+);
}
}
bool getit(int x,int k,int j){
if(k<j){
if(e[x].exist){
printf("%s",&e[x].ch);
return ;
}
return ;
}
int z=a[j]-'a';
if(e[x].next[z]){
return getit(e[x].next[z],k,j+);
}else{
return ;
}
}
int main(){
while(scanf("%s",&b)){
if(strcmp(b,st)==){
continue;
}if(strcmp(b,ed)==){
break;
}
scanf("%s",&a);
doit(,strlen(a)-,);
}
scanf("%s",&b);
a[]=getchar();
a[]=getchar();
int i=;
while(a[]!='E'){
while(a[i]<='z'&&a[i]>='a'){
i++;
a[i]=getchar();
}
cc=a[i];
a[i]=;
if(i>){
if(!getit(,i-,)){
for(int j=;j<i;j++){
printf("%c",a[j]);
}
}
}
printf("%c",cc);
i=;
a[]=getchar();
}
return ;
}
HDU 1057 What Are You Talking About trie树 简单的更多相关文章
- HDU 11488 Hyper Prefix Sets (字符串-Trie树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
- HDU1251 统计难题 trie树 简单
http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意: 找前缀数量 裸模板 #include<cstdio> #include<cstr ...
- AVL树,红黑树,B-B+树,Trie树原理和应用
前言:本文章来源于我在知乎上回答的一个问题 AVL树,红黑树,B树,B+树,Trie树都分别应用在哪些现实场景中? 看完后您可能会了解到这些数据结构大致的原理及为什么用在这些场景,文章并不涉及具体操作 ...
- HDU 1251 Trie树模板题
1.HDU 1251 统计难题 Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...
- HDU 5269 ZYB loves Xor I Trie树
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5269 bc:http://bestcoder.hdu.edu.cn/contests/con ...
- hdu 5269 trie树
现场想到了lowbit(X xor Y)=X和Y从右向左数,对应相同的数的个数+1...然而并没有想到接下来用trie树 然后就想排个序试试...然后就整个人都不好了啊摔 sol:用trie,一边in ...
- hdu 4099 Revenge of Fibonacci Trie树与模拟数位加法
Revenge of Fibonacci 题意:给定fibonacci数列的前100000项的前n位(n<=40);问你这是fibonacci数列第几项的前缀?如若不在前100000项范围内,输 ...
- HDU 1251 统计难题 (字符串-Trie树)
统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...
- 【HDU - 5790 】Prefix(主席树+Trie树)
BUPT2017 wintertraining(15) #7C 题意 求[min((Z+L)%N,(Z+R)%N)+1,max((Z+L)%N,(Z+R)%N)+1]中不同前缀的个数,Z是上次询问的结 ...
随机推荐
- composer 上提交自己的包
先在github上复制自己的地址在 https://packagist.org/packages/submit ->check->submit
- linux下C语言实现多线程通信—环形缓冲区,可用于生产者(producer)/消费者(consumer)【转】
转自:http://blog.chinaunix.net/uid-28458801-id-4262445.html 操作系统:ubuntu10.04 前言: 在嵌入式开发中,只要是带操作系统的 ...
- python selenium登陆网易云音乐
from selenium import webdriver import time driver=webdriver.Chrome() driver.get("http://music.1 ...
- 微信access_token和refresh_token保存于redis
简介 通常理解的access_token和refresh_token access_token是用来对客户端进行认证的,类似与密码,有一定的有效期.当过期后可使用refresh_token重新获取一个 ...
- Freemaker语法
包含文件 <a href="${latestProduct.url}">${latestProduct.name}</a> 基本语法 ${...}:Free ...
- leetcode 之Remove Duplicates from Sorted Array(2)
描述 Follow up for ”Remove Duplicates”: What if duplicates are allowed at most twice? For exampl ...
- cfg 4 ocl
http://blog.sina.com.cn/s/blog_6c868c470102v15y.html rnnlib真难装 http://sourceforge.net/p/rnnl/wiki/Ho ...
- 前端代码编辑器ace 语法验证
本文主要是介绍实际项目中如何加入语法检测功能.官方文档链接https://github.com/ajaxorg/ace/wiki/Syntax-validation 代码编辑器ace,使用webwor ...
- yii2 GirdView使用全教程
开始GridView GridView主要是为了实现表格复用,尤其我们做后台的时候,你发现表单和表格占据了大部分页面,而表格的样式又是高度的统一,那么如果有这样一个挂件,传入数据集自动渲染表格该多好. ...
- HTML canvas fillText()与measureText()方法
HTML5 canvas fillText() 方法 实例 使用 fillText(),在画布上写文本 "你好!word!" 和 "我是w3c": JavaSc ...