【题解】UVA11362 Phone List
Tags :
排序,字典树
从短到长排序,逐个插入字典树。若与已有的重复,返回错误信息。
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <algorithm>
#define re register
#define GC getchar()
#define Clean(X,K) memset(X,K,sizeof(X))
using namespace std ;
const int Maxn = 10005 , MaxD = 10 , Base = 10 ;
int Times , N , T[Maxn * MaxD][Base] , End[Maxn * MaxD] , Tot = 0;
string S[Maxn] ;
bool Add (string &S) {
int L = S.length() , P = 0 ;
for (re int i = 0 ; i < L; ++ i) {
if (!T[P][S[i] - '0']) T[P][S[i] - '0'] = ++ Tot ;
P = T[P][S[i] - '0'] ;
if (End[P]) return true ;
}
++ End[P] ;
return false ;
}
bool C (const string &X , const string &Y) {
return X.length() < Y.length() ;
}
int main () {
// freopen ("POJ3630.in" , "r" , stdin) ;
scanf ("%d" , &Times) ;
while (Times -- ) {
scanf ("%d\n" , &N) ;
Clean (T , 0) , Clean (End , 0);
Tot = 0 ;
bool Fl = true ;
for (re int i = 0 ; i < N; ++ i) getline (cin , S[i]) ;
sort (S , S + N , C) ;
for (re int i = 0 ; i < N; ++ i) {
if (Add (S[i])) {
printf("NO\n") ;
Fl = false;
break ;
}
}
if (Fl ) printf ("YES\n") ;
}
fclose (stdin) , fclose (stdout) ;
return 0 ;
}
【题解】UVA11362 Phone List的更多相关文章
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 网络流n题 题解
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...
- CF100965C题解..
求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...
随机推荐
- Luogu P5292 [HNOI2019]校园旅行
非常妙的一道思博题啊,不愧是myy出的题 首先我们考虑一个暴力DP,直接开一个数组\(f_{i,j}\)表示\(i\to j\)的路径能否构成回文串 考虑直接拿一个队列来转移,队列里存的都是\(f_{ ...
- python基础-函数(9)
一.函数的介绍 如果在开发程序时,需要某块代码多次,但是为了提高编写的效率以及代码的重用,所以把具有独立功能的代码块组织为一个小模块,这就是函数 函数的语法格式: def 函数名(): 函数的功能代码 ...
- 用SpringCloud进行微服务架构演进
在<架构师必须要知道的阿里的中台战略与微服务> 中已经阐明选择SpringCloud进行微服务架构实现中台战略,因此下面介绍SpringCloud的一些内容,SpringCloud已经出来 ...
- 详解MySQL表空间以及ibdata1文件过大问题
ibdata1文件过大 原因分析 ibdata1是一个用来构建innodb系统表空间的文件,关于系统表空间详细介绍参考MySQL官网文档 上面是一个数据库的ibdata1文件,达到了780多G,而且还 ...
- 权限管理系统之SpringBoot集成LayUI实现后台管理首页
万事开头难,昨天一直在构思用户权限管理系统怎么实现,实现哪些需求,采用什么技术等,也在网上百度了好多,计划使用SpringBoot + Mybatis + thymeleaf + LayUI + S ...
- App.config自定义节点读取
<?xml version="1.0" encoding="utf-8"?> <configuration> <!--<ot ...
- [MySQL] MVCC 多版本并发控制实现的事务
1.没有一个统一的实现标准,实现了非阻塞的读操作,写操作也只锁定必要的行2.通过保存数据在某个时间点的快照实现的3.典型的有乐观并发控制和悲观并发控制4.innodb的mvcc是每次事务都有递增的版本 ...
- Java Calendar类使用总结
平时在浏览一些网站时,有些网站会显示出当前时间,如现在是xx年xx月xx日 xx时xx分xx秒,在实际的开发过程中,也会涉及到日期和时间的计算,Java中提供了一个专门的类Calendar来处理日期与 ...
- Unable to execute 'doFinal' with cipher instance [javax.crypto.Cipher@4e025e0a]
org.apache.shiro.crypto.CryptoException: Unable to execute 'doFinal' with cipher instance [javax.cry ...
- java的设计模式 - Builder模式
Builder 模式的目的? 构造对象的方式过于复杂,不如将之抽离出来.比如,构造器参数过多 这样说也有点抽象,举个例子吧. 举个例子 比如 非常热门的消息队列RabbitMQ 的 AMQP.Basi ...