AC日记——统计难题 hdu 1251
统计难题
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 36637 Accepted Submission(s):
13622
注意:本题只有一组测试数据,处理到文件结束.
band
bee
absolute
acm
ba
b
band
abc
3
1
0
#include <string>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; struct TreeNode {
short num;
bool if_[];
struct TreeNode *word[];
}; class TrieTreeType {
private:
struct TreeNode *null; public:
struct TreeNode *root; TrieTreeType()
{
null=new TreeNode;
null->num=;
for(int i=;i<=;i++) null->if_[i]=false;
for(int i=;i<=;i++) null->word[i]=null;
root=new TreeNode;
root->num=;
for(int i=;i<=;i++) root->if_[i]=false;
for(int i=;i<=;i++) root->word[i]=null;
} inline void Insert(char str[])
{
TreeNode *now=root;
now->num++;
int len=strlen(str);
for(int v=;v<len;v++)
{
if(!now->if_[str[v]-'a'])
{
now->word[str[v]-'a']=new TreeNode;
now->word[str[v]-'a']->num=;
for(int i=;i<=;i++) now->word[str[v]-'a']->if_[i]=false;
for(int i=;i<=;i++) now->word[str[v]-'a']->word[i]=null;
now->if_[str[v]-'a']=true;
}
now=now->word[str[v]-'a'];
now->num++;
}
} inline int Size(char str[])
{
TreeNode *now=root;
int len=strlen(str);
for(int v=;v<len;v++)
{
if(now->word[str[v]-'a']==null) return ;
now=now->word[str[v]-'a'];
}
return now->num;
}
};
class TrieTreeType tree; int len_sen,n; char sen[]; bool if_c=false; int main()
{
while(gets(sen))
{
if(strlen(sen)==)
{
if_c=true;
continue;
}
if(if_c) printf("%d\n",tree.Size(sen));
else tree.Insert(sen);
}
return ;
}
AC日记——统计难题 hdu 1251的更多相关文章
- 字典树模板题(统计难题 HDU - 1251)
https://vjudge.net/problem/HDU-1251 标准的字典树模板题: 也注意一下输入方法: #include<iostream> #include<cstdi ...
- 统计难题 HDOJ --1251
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- AC日记——统计单词数 openjudge 1.12 5
05:统计单词数 总时间限制: 1000ms 内存限制: 65536kB 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...
- AC日记——统计数字字符个数 openjudge 1.7 01
01:统计数字字符个数 总时间限制: 1000ms 内存限制: 65536kB 描述 输入一行字符,统计出其中数字字符的个数. 输入 一行字符串,总长度不超过255. 输出 输出为1行,输出字符串 ...
- AC日记——Keywords Search hdu 2222
2222 思路: ac自动机模板题: 代码: #include <cstdio> #include <cstring> #include <iostream> #i ...
- AC日记——Number Sequence hdu 1711
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- AC日记——病毒侵袭 hdu 2896
2896 思路: 好题: 代码: #include <queue> #include <cstdio> #include <cstring> using names ...
- AC日记——Paint Pearls hdu 5009
Paint Pearls 思路: 离散化+dp+剪枝: dp是个n方的做法: 重要就在剪枝: 如果一个长度为n的区间,有大于根号n种颜色,还不如一个一个涂: 来,上代码: #include <c ...
- AC日记——Super Mario hdu 4417
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- 自定义View常处理的回调函数
自定义View常处理的回调函数 onFinishInflate() 当View中所有的子控件均被映射成xml后触发 onMeasure(int, int) 确定所有子元素的大小 onLayout(bo ...
- iptables-过滤61开头的ip数据包
iptables -F root@android:/system/bin # iptables -L -n iptables -L -n Chain INPUT (policy ACCEPT) tar ...
- Python3基础 函数名.__doc__显示一个函数的单行与多行函数文档
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- Android音频系统之AudioFlinger(二)
1.1.1 音频设备的管理 虽然AudioFlinger实体已经成功创建并初始化,但到目前为止它还是一块静态的内存空间,没有涉及到具体的工作. 从职能分布上来讲,AudioPolicyService是 ...
- eclipse's code assist
突然发现有个类没有code assist功能了,而别的类都还有,新建的类也有,可是当把代码拷贝到新建的类还是不行:尝试了各种办法,包括删除workspace/.metadata/.plugin/org ...
- SpringMVC文件上传报错org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
错误信息: java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to or ...
- CG之基本光照模型计算公式
在一个基本模型里,一个物体表面的颜色是由放射(emissive).环境反射(ambient).漫反射(diffuse)和镜面反射(specular)等光照作用的总和.每种光照作用取决于表面材质的性质( ...
- iOS之PCH文件
在Xcode6之前,创建一个新工程xcode会在Supporting files文件夹下面自动创建一个“工程名-Prefix.pch”文件,也是一个头文件,pch头文件的内容能被项目中的其他所有源文件 ...
- Oracle教程-安装、结构(一)
本文安装的是Oracle中的11G版本 一. 将文件win32_11gR2_database_1of2.zip和win32_11gR2_database_2of2.zip解压. 注意:这两个文件解压到 ...
- (中等) POJ 2482 Stars in Your Window,静态二叉树。
Description Here comes the problem: Assume the sky is a flat plane. All the stars lie on it with a l ...