hdoj1251-统计难题 【字典树】
http://acm.hdu.edu.cn/showproblem.php?pid=1251
统计难题
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 19902 Accepted Submission(s): 8720
注意:本题只有一组测试数据,处理到文件结束.
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <algorithm>
- #include <string>
- #include <map>
- using namespace std;
- #define MAX 0x7fffffff
- struct node{
- node* word[];
- int n;
- node(){
- for(int i=;i<;i++) word[i]=NULL;
- n=;
- }
- }*root;
- void Insert(char* s);
- int Find(char* s);
- int main(){
- //freopen("D:\\input.in","r",stdin);
- //freopen("D:\\output.out","w",stdout);
- char tmp[];
- root=new node;
- while(gets(tmp),strlen(tmp)){
- Insert(tmp);
- }
- while(gets(tmp)!=NULL){
- printf("%d\n",Find(tmp));
- }
- return ;
- }
- void Insert(char* s){
- int len=strlen(s);
- node *current=root,*new_node;
- for(int i=;i<len;i++){
- if(current->word[s[i]-'a']!=NULL){
- current=current->word[s[i]-'a'];
- current->n++;
- }else{
- new_node=new node;
- current->word[s[i]-'a']=new_node;
- current=current->word[s[i]-'a'];
- }
- }
- }
- int Find(char* s){
- int len=strlen(s);
- node *current=root;
- for(int i=;i<len;i++){
- if(current->word[s[i]-'a']!=NULL){
- current=current->word[s[i]-'a'];
- }else{ return ; }
- }
- return current->n;
- }
hdoj1251-统计难题 【字典树】的更多相关文章
- hdoj1251 统计难题 字典树
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
- hdu_1251统计难题(字典树Trie)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu 1251 统计难题 字典树第一题。
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu 1251 统计难题(字典树)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- HDU-1251 统计难题,字典树或者map!
统计难题 很久就看过这个题了,但不会~~~不会~~ 题意:给出一张单词表,然后下面有若干查询,每次给出一个单词,问单词表中是否存在以这个单词为前缀的单词,输出数量.本身也是自身的前缀.只有一组数据! ...
- HDU 1251 统计难题 字典树大水题
今天刚看的字典树, 就RE了一发, 字典树原理还是很简单的, 唯一的问题就是不知道一维够不够用, 就开的贼大, 这真的是容易MLE的东西啊, 赶紧去学优化吧. HDU-1251 统计难题 这道题唯一的 ...
- hdu 1251 统计难题 (字典树(Trie)<PS:C++提交不得爆内存>)
统计难题Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submis ...
- hdoj 1251 统计难题(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 思路分析:该问题要求求出以某个字符串为前缀的单词数目,通过使用字典树,在字典树中添加count记 ...
随机推荐
- 转转转!!java基础一些静态代码块等知识点
一.代码块: 构造代码块------类中方法的外面:每次调用构造方法都执行: 静态代码块------类中方法的外面,括号前加上static:只执行一次,随着类的加载而执行: static代码块.构造代 ...
- Spring 注解方式 实现 IOC 和 DI
注:以下所有测试案例(最后一个除外)的测试代码都是同一个: package cn.tedu.test; import org.junit.Test; import org.springframewor ...
- img atl和a title
今天发现一个有趣的现象. <a href="#" title="a"><img src="xxx.jpg" alt=& ...
- Vmware 安装CentOS 6.5
转自:http://www.centoscn.com/image-text/install/2014/1209/4281.html 其实通过VM安装虚拟机还是蛮简单的,只不过有个别选项可能导致大家安装 ...
- PAT-甲级刷题笔记和总结
本帖主要记录一些自己在刷题过程中的一些笔记,包括: 1.常用的函数 2.STL中常用方法 3.常见错误 4.其他常用方法 5.刷题过程中的常见算法:https://www.cnblogs.com/M ...
- PostMan 使用Interceptor 发送带cookie的请求一直loading
问题 最近要写一个爬虫(虽然是第一次写),于是就用了Chrome上非常方便一个插件,PostMan,但是由于chrome安全的限制,发不出带cookie和带有自定义头部标签的请求. 百度一番后得如果想 ...
- jpgraph中文使用手册之文本和字体控制教程
摘要:在之前的php jpgraph安装配置教程中已介绍过jpgraph字体的安装与配置方法,jpgraph类库中字体和文本的使用是非常重要的,jpgraph既可以控 制文本的旋转.对齐方式.字体大小 ...
- 向Nexus仓库推送/使用各种组件
1.Nuget仓库 使用NuGetPackageExplorer打包制作自己的nupkg https://github.com/NuGetPackageExplorer/NuGetPackageExp ...
- ioncube 加密软件 linux 使用方法
https://www.ioncube.com/sa_encoder.php?page=pricing 购买成功后 解压文件包 装了一个linux 版的加密软件 目录:/webdata/soft/io ...
- X-Requested-With
最近工作中发现,使用angular $http跨域的时候,虽然后台已经配置了跨域允许,但是还是报错. 查资料发现,angular $http 的request的请求头中,默认有: Access-Con ...