首页 技术 正文
技术 2022年11月15日
0 收藏 965 点赞 4,641 浏览 1046 个字

题目链接:https://www.facebook.com/hackercup/problems.php?pid=313229895540583&round=344496159068801

题目大意:自己看去(其实我也说不清)

裸的Trie树,直接看是否存在必须插入的节点。

代码写的太挫了。。将就着看吧。。

 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdlib>
using namespace std;
#define CHARSET 26 const int MAX_NODE = ; struct trieNode{
int ch[CHARSET];
};
trieNode trie[MAX_NODE];
int ptr;
int ans; int T,N;
char str[MAX_NODE]; void init(){
ptr = ans = ;
for(int i=;i<CHARSET;i++){
trie[].ch[i] = -;
}
} int newNode(){
ptr++;
for(int i=;i<CHARSET;i++){
trie[ptr].ch[i] = -;
}
return ptr;
} void insert(const char* str){
bool hasAdded = false;
int len = strlen(str);
int rt = ;
for(int i=;i<len;i++){
int id = str[i] - 'a';
if( trie[rt].ch[id]==- ){
trie[rt].ch[id] = newNode();
if( !hasAdded ){
ans = ans + i + ;
hasAdded = true;
// printf("+%d\n",i+1);
}
}
rt = trie[rt].ch[id];
}
if(!hasAdded){
ans = ans + len;
// printf("+%d\n",len);
}
} int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
scanf("%d",&T);
for(int cases = ;cases <= T ; cases++){
scanf("%d",&N);
init();
for(int i=;i<N;i++){
scanf("%s",str);
insert(str);
}
printf("Case #%d: %d\n",cases,ans);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,484
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,899
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,732
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,485
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,125
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,286