HDU1671 水题字典树
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int T,trie[][],n,cnt;
int f[];
char c[];
bool flag;
void _insert()
{
int L=strlen(c+),tmp=;
for(int i=;i<L;i++){
if(!trie[tmp][c[i]-'']) trie[tmp][c[i]-'']=++cnt;
tmp=trie[tmp][c[i]-''];
if(f[tmp]) flag=false;
}//最后一位单独判断
if(trie[tmp][c[L]-'']) flag=false;
else trie[tmp][c[L]-'']=++cnt;
f[trie[tmp][c[L]-'']]=;
}
int main()
{
scanf("%d",&T);
while(T--){
scanf("%d",&n);
memset(trie,,sizeof(trie));
memset(f,,sizeof(f));//记录是否为单词尾字母
flag=true;cnt=;
for(int i=;i<=n;i++){
scanf("%s",c+);
if(flag) _insert();
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return ;
}
HDU1671 水题字典树的更多相关文章
- HDU1305 Immediate Decodability(水题字典树)
巧了,昨天刚刚写了个字典树,手到擒来,233. Problem Description An encoding of a set of symbols is said to be immediatel ...
- C#LeetCode刷题-字典树
字典树篇 # 题名 刷题 通过率 难度 208 实现 Trie (前缀树) 48.6% 中等 211 添加与搜索单词 - 数据结构设计 39.9% 中等 212 单词搜索 II 27.9% ...
- hdu1671 Phone List [字典树 hash]
传送门 Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hihoCoder 1014trie树(字典树)
hihoCoder 1014 题目提示已经很清楚了~ 贴代码…… #include <iostream> #include <cstdio> #include <cstr ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- hdu1305 字典树水题
题意: 给你一些字符串,然后问你他们中有没有一个串是另一个串的前缀. 思路: 字典树水题,(这种水题如果数据不大(这个题目不知道大不大,题目没说估计不大),hash下也行,把每个 ...
- HDU 1247 - Hat’s Words - [字典树水题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...
- CDOJ 1060 秋实大哥与快餐店 字典树 水题
题目链接 B - 秋实大哥与快餐店 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu Sub ...
- bzoj1103树状数组水题
(卧槽,居然规定了修改的两点直接相连,亏我想半天) 非常水的题,用dfs序(而且不用重复,应该是直接规模为n的dfs序)+树状数组可以轻松水 收获:树状数组一遍A(没啥好骄傲的,那么简单的东西) #i ...
随机推荐
- codeforces Round#429 (Div2)
2017-08-20 10:00:37 writer:pprp 用头文件#include <bits/stdc++.h>很方便 A. Generous Kefa codeforces 84 ...
- Zookeeper Zkclient客户端
Zkclient是对Zookeeper的原生API进行了包装,实现了超时重连.Watcher反复注册等功能,它可以实现递归创建,删除节点,但是zkClient不能递归给节点赋值. 主要的api如下: ...
- Android安装过程出现问题
Android安装过程出现问题 一.Eclipse 中 Emulator Control 不能用问题 在官方文档中发现问题所在(官方文档说明),在最后一行“The Emulator Control t ...
- nginx 日志搜集解决方案
# nginx 日志搜集解决方案 ## 系统环境描述 ``` java8 logstash --监控nginx日志文件 ``` ## 技术描述 ``` 通过logstash监控nginx access ...
- 利用python 模块读取csv文件信息
还有一个比较简单的方法 # -*- coding=utf-8 -*- import pandas as pddf = pd.read_csv("20170320094630.csv" ...
- ContentPresenter元素
一个内容控件 分解它的“结构树”,肯定能够看到ContentPresenter“元素”,该元素的功能:用来为“内容控件”显示“Content”
- jQuery 获取Select选择的Text和 Value
jQuery获取Select选择的Text和Value:语法解释: 1. $("#select_id").change(function(){//code...}); / ...
- 作业列表 of《软件测试技术》
作业1(截止时间3月22日) 请使用excel模板或word模板,完成对126邮箱登录功能的测试用例编写,界面如下图.提交到ftp. --------------------------------- ...
- 关于mybatis mapper.xml中的if判断
场景: 页面上有搜索框进行调节查询,不同搜索框中的内容可以为空. 过程: 点击搜索,前端把参数传给后台,这是后台要把为空的参数过滤掉. 做法: 通常我们在dao层即mapper.xml中进行过滤判断操 ...
- nyi63——树
#include<bits/stdc++.h> using namespace std; int cnt; struct node { int data; int flag; node * ...