HDOJ-1671 Phone List
Phone List
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
1. Emergency 911
2. Alice 97 625 999
3. Bob 91 12 54 26
In this case, it’s not possible to call Bob, because the central would direct your call to the emergency line as soon as you had dialled the first three digits of Bob’s phone number. So this list would not be consistent.
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=; struct node{
int m;
int v;
node *next[];
node()
{
for(int i=;i<;i++)
next[i]=NULL;
m=;
}
}; node *root;
int n;
bool flag; void insert_tree(char* str)
{
int len=strlen(str);
if(root==NULL)
root=new node;
node *p=root,*q;
for(int i=;i<len;i++)
{
if(p->m==)
{
flag=true;
return; //the end
}
int id=str[i]-'';
if(p->next[id]==NULL)
{
q=new node;
p->next[id]=q;
p=p->next[id];
}
else
{
p=p->next[id];
if(i==len-)
{
flag=true;
return; //the end;
}
}
if(i==len-)
{
p->m=;
}
}
} void del_tree(node* rt)
{
for(int i=;i<;i++)
{
if(rt->next[i]!=NULL)
del_tree(rt->next[i]);
}
delete rt;
} int main()
{
int t;
char str[maxn];
scanf("%d",&t);
while(t--)
{
flag=false;
root=NULL;
scanf("%d",&n);
while(n--)
{
scanf("%s",str);
if(flag)
continue;
else
insert_tree(str);
}
if(flag)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
del_tree(root);
}
return ;
}
HDOJ-1671 Phone List的更多相关文章
- 字典树trie的学习与练习题
博客详解: http://www.cnblogs.com/huangxincheng/archive/2012/11/25/2788268.html http://eriol.iteye.com/bl ...
- <转Tanky Woo> 字典树
又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优点是:利用字符串的公共前缀 ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- hdoj 1385Minimum Transport Cost
卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...
- HDOJ(2056)&HDOJ(1086)
Rectangles HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...
- 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ
前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...
- 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design
题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...
随机推荐
- ios 导航视图控制器 跳转
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...
- SummerVocation_Learning--java的线程机制
线程:是一个程序内部的执行路径.普通程序只有main()一条路径.如下列程序: import java.lang.Thread; //导入线程实现包 public class Test_Thread ...
- zabbix 密码忘记了如何恢复
1.进入数据库 2.使用zabbix的数据库 use zabbix: 3.查看表信息 show tables; 4.搜索users表 select * from users; 5.修改userid为1 ...
- Linux 连接 Internet
本文根据<鸟哥的Linux私房菜-服务器架设篇>第四章总结 Linux 连接 Internet 前的注意事项 想要连接 Internet 需要配置一组合法的 IP 参数,主要是 IP.Ne ...
- C盘扩容 更改C盘大小
最近对xamarin有点兴趣,虽然网上的评论嘘声一片, 对于只想试一试的心态来说,对于网上所说的什么开发后的程序卡顿,可以用的三方库很少等, 我只想说,你们说的我不信,我要试一试看 我本来已经安装了v ...
- DeepFaceLab进阶(4):通过Colab免费使用Tesla K80 跑模型!
当学会了换脸软件DeepFaceLab基本使用,各种参数配置,各有优化技能之后.唯一约束你的可能是电脑配置. CPU能跑,但是慢到怀疑人生,低配模型都得跑一周 低配显卡,显存不够,H128 根本就跑不 ...
- url传参及重定向
成功跳转$this -> success('提示语',跳转路径,返回的数据,时间,发送的 Header 信息)跳转失败$this -> error('提示语',跳转路径,返回的数据,时间, ...
- django开发傻瓜教程-1-安装和HelloWorld
安装 sudo pip install Django 新建项目 django-admin startproject XXX 启动项目 进入主目录下 python manage.py runserver ...
- Susan Sontag【苏珊·桑塔格】
Sunsan Sontag Sunsan Sontag was one of the most noticeable figures in the world of literature. 苏珊·桑塔 ...
- Kinect安装
在连接kinect机器前,需要先安装两个软件,而在安装这两个软件前需要有vs2010(专业版本和快速版),因为需要包含.net framework 4.0 kinect sdk http://www. ...