题目:给你一组电话号码,推断是否有一些号码是其它的前缀(或相等)。

分析:字符串。字典树。利用字典树储存查询就可以,注意两种情况处理:

1.先短后长(前缀在前);2.先长后短(前缀在后)。

说明:第580题了,目标600╮(╯▽╰)╭。

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath> using namespace std; #define nodesize 100001 //节点个数
#define dictsize 128 //字符集大小 //trie
typedef struct node1
{
int flag; //值域
node1* next[dictsize];
}tnode;
tnode dict[nodesize]; class Trie
{
private:
int size;
tnode* root;
public:
Trie() {initial();}
void initial() {
memset(dict, 0, sizeof(dict));
size = 0; root = newnode();
}
tnode* newnode() {return &dict[size ++];}
int insert(char* word) {
tnode* now = root;
for (int i = 0 ; word[i] ; ++ i) {
if (!now->next[word[i]])
now->next[word[i]] = newnode();
now = now->next[word[i]];
if (now->flag) return 1;
}now->flag = 1;
for (int i = 0 ; i < dictsize ; ++ i)
if (now->next[i])
return 1;
return 0;
}
}trie;
//trie end int main()
{
int t,n;
char buf[12];
while (~scanf("%d",&t))
while (t --) {
trie.initial();
scanf("%d",&n);
int flag = 0;
for (int i = 0 ; i < n ; ++ i) {
scanf("%s",buf);
if (trie.insert(buf))
flag = 1;
} if (flag)
printf("NO\n");
else printf("YES\n");
}
return 0;
}

UVa 11362 - Phone List的更多相关文章

  1. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  2. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  3. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  4. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  5. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  6. UVA数学入门训练Round1[6]

    UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...

  7. UVA - 1625 Color Length[序列DP 代价计算技巧]

    UVA - 1625 Color Length   白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束   和模拟赛那道环形DP很想,计算这 ...

  8. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  9. UVA - 11584 Partitioning by Palindromes[序列DP]

    UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...

随机推荐

  1. Ionic2/angularJs2中的静态类 PhotoLibrary 调用不上

    photoLibrary调用报错:No provider for PhotoLibrary: 在调用相册文件时有用到photolibrary,总有些莫名的报错,3月份的时候这个坑让我不知所措,现在写下 ...

  2. 解决 HTTP Status 500 - Unable to show problem report: freemarker.core.InvalidReferenceException:

    HTTP Status 500 - Unable to show problem report: freemarker.core.InvalidReferenceException: The foll ...

  3. jsp学习笔记 - 内置对象 pageContext

    1.pageContext几乎可以操作所有的页面内置对象 pageContext.getRequest();    得到的对象只是属于ServletRequest类,httpServletReques ...

  4. ubuntu+ngnix+thinkphp pathinfo配置

    一.thinkphp 项目改为pathinfo模式 XXX/ThinkPHP/Conf/convention.php文件中找到 'URL_MODEL' => 1, // URL访问模式,可选参数 ...

  5. Stack frame

    http://en.citizendium.org/wiki/Stack_frame In computer science, a stack frame is a memory management ...

  6. MFC_2.3 定时器、滑块、进度条控件

    定时器.滑块.进度条控件 1.拖控件 2.绑定变量.默认,然后取名字 3.初始化设置定时器 // 设置滑块和进度条的范围 m_TrackBar.SetRange(0, 1000); m_StaticP ...

  7. vue基础---列表渲染

    首先简单回顾下v-for‘指令 <ol id="list_area"> <li v-for="book in books">{{book ...

  8. flipt 一个基于golang 的特性工具开发类库

    以前介绍过一个Flagr 的基于golang 的特性功能开发类库(技术雷达推荐),今天看到一个类似也很不错的方案flipt 参考架构 包含的特性 快速,使用golang 编写,同时进行了性能优化 运行 ...

  9. 1007 Maximum Subsequence Sum (PAT(Advance))

    1007 Maximum Subsequence Sum (25 分)   Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A ...

  10. 怎么提交小程序给微信?微信小程序的提交审核流程

    开发者开发好一款微信小程序后,如何将其提交给微信审核呢?今天正好有空,就整理了一下小程序的提交流程,以供大家参考.如果要发布小程序,那么你需要申请真正的小程序账号,拿到appId,才能在手机预览.及提 ...