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 ...
随机推荐
- zf-关于注册码全部错误的解决方法
之所以错误,是因为这里的用户名称是石首市政务服务中心. 在数据库里把这个字段改成 上海卓繁 就可以了 一般都是在 SYS_INFO 这张表里面改
- URL 传+号到后台变空格问题解决方案
今天巧合遇到这个问题,下面是网上找的解决方案. 原文:http://blog.sina.com.cn/s/blog_a0949eec01010xta.html 今天在调试客户端向服务器传递参数时,参数 ...
- java socket 多线程网络传输多个文件
http://blog.csdn.net/njchenyi/article/details/9072845 java socket 多线程网络传输多个文件 2013-06-10 21:26 3596人 ...
- 深入浅出 - Android系统移植与平台开发(一)
深入浅出 - Android系统移植与平台开发(一) 分类: Android移植2012-09-05 14:16 16173人阅读 评论(12) 收藏 举报 androidgitgooglejdkub ...
- linux下 mysql 学习(一)
1.登录mysql [root@test1 local]# mysql Welcome to the MySQL monitor. Commands end with ; or g. Your My ...
- openstack controller ha测试环境搭建记录(十四)——配置cinder(存储节点)
先简述cinder存储节点的配置: 1.IP地址是10.0.0.41: 2.主机名被设置为block1: 3.所有节点的hosts文件已添加相应条目: 4.已经配置了ntp时间同步: 5.已 ...
- CodeForces 598E Chocolate Bar
区间DP预处理. dp[i][j][k]表示大小为i*j的巧克力块,切出k块的最小代价. #include<cstdio> #include<cstring> #include ...
- CDOJ 1269 ZhangYu Speech
预处理打表,sum[i][j]表示1.....i这些数字中 j 有几个.然后就很好处理询问了. #include<stdio.h> #include<math.h> #incl ...
- Linux下hosts、host.conf、resolv.conf
/etc/resolv.conf 该文件是DNS域名解析的配置文件,它的格式很简单,每行以一个关键字开头,后接配置参数. resolv.conf的关键字主要有四个,分别是: nameserver ...
- /bin/sh 与 /bin/bash 的区别
/bin/sh 与 /bin/bash 的区别,用 : 截取字符串不是POSIX 标准的. 区别 sh 一般设成 bash 的软链 (symlink) ls -l /bin/sh lrwxrwxrwx ...