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 ...
随机推荐
- call_grant_exec.sql
set echo off feedback off verify off pagesize 0 linesize 120 define v_grantee = & ...
- FusionCharts使用问题及解决方法(一)-FusionCharts常见问题大全
当你利用FusionCharts创建图表时报错,原因是多方面的.本文总结了一些常见问题及解决方法供大家参考,希望对大家有帮助. 如果你无法看到任何图表: 如果浏览器中的进度条一直加载,或者右键菜单显示 ...
- Copy-->Mutable Copy
一.深拷贝和浅拷贝 深拷贝:对象拷贝 - 直接拷贝内容. 浅拷贝:指针拷贝 - 将指针中的地址值拷贝一份. 二.对于 Copy 与 mutableCopy 的实践 思路:我用四个方案来验证 Copy ...
- linux系统下c程序分多文件实现
对于一个整数数组排序,按从小到大排序,数组元素个数不定.要求多文件实现 1,排序的函数作为一个文件 输出结果作为一个程序 主函数作为一个文件 运行程序 gcc -o main main.c paixu ...
- Activity进程和线程之间的关系
1,四大组件并不是程序(进程)的全部,只是他的零件. 2,应用程序启动后,将创建ActivityThread主线程. 3,同一包中的组件将运行在想通的进程空间里面. 4,不同包中的组件可以通过一定的方 ...
- webView.loadUrl("file:///android_asset/table3.html")出现中文乱码的问题
webSettings.setDefaultTextEncodingName("UTF-8");
- git使用时遭遇the authenticity of host can't be established
修改/etc/ssh/ssh_config文件的配置,以后则不会再出现此问题 最后面添加: StrictHostKeyChecking no UserKnownHostsFile /dev/null
- Struts2--简单的数据校验
action没有request, response等属性, 无法往前台传信息, 出来一个概念, valuestack: 存放action的属性, 还有各种error等... <s:propert ...
- CodeForces 616C The Labyrinth
先预处理出所有连通块,对于每一个*,看他四周的连通块即可 #include<cstdio> #include<cstring> #include<queue> #i ...
- CodeForces 616A Comparing Two Long Integers
水题 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; +; ...