poj 3630 Phone List 贪心
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 23722 | Accepted: 7289 |
Description
Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let's say the phone catalogue listed these numbers:
- Emergency 911
- Alice 97 625 999
- 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.
Input
The first line of input gives a single integer, 1 ≤ t ≤ 40, the number of test cases. Each test case starts with n, the number of phone numbers, on a separate line, 1 ≤ n ≤ 10000. Then follows n lines with one unique phone number on each line. A phone number is a sequence of at most ten digits.
Output
For each test case, output "YES" if the list is consistent, or "NO" otherwise.
Sample Input
2
3
911
97625999
91125426
5
113
12340
123440
12345
98346
Sample Output
NO
YES
题意是,给你N个数字,然后问你里面有没有一些数字是另外一些数字的前缀,如果是的话,就输出NO,不是的话就输出YES
唔,正版做法我觉得应该是字典树
但是这道题可以取巧,直接按照字典序大小,sort一下,然后比较a[i]和a[i+1],看看a[i]是不是a[i+1]的前缀啥的~
string a[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
cin>>n;
vector<string> s;
string ss;
for(int i=;i<n;i++)
{
cin>>ss;
s.push_back(ss);
}
sort(s.begin(),s.end());
int flag=;
for(int i=;i<n-;i++)
{
if(s[i+].find(s[i])==)
flag=;
}
if(flag==)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
}
poj 3630 Phone List 贪心的更多相关文章
- POJ 3190 Stall Reservations贪心
POJ 3190 Stall Reservations贪心 Description Oh those picky N (1 <= N <= 50,000) cows! They are s ...
- POJ 2392 Space Elevator(贪心+多重背包)
POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...
- POJ 2376 Cleaning Shifts 贪心
Cleaning Shifts 题目连接: http://poj.org/problem?id=2376 Description Farmer John is assigning some of hi ...
- poj 1659 Frogs' Neighborhood (贪心 + 判断度数序列是否可图)
Frogs' Neighborhood Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 6076 Accepted: 26 ...
- POJ 3045 Cow Acrobats (贪心)
POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一 ...
- 【POJ 3614 Sunscreen】贪心 优先级队列
题目链接:http://poj.org/problem?id=3614 题意:C头牛去晒太阳,每头牛有自己所限定的spf安全范围[min, max]:有L瓶防晒液,每瓶有自己的spf值和容量(能供几头 ...
- POJ 3630 Phone List(trie树的简单应用)
题目链接:http://poj.org/problem?id=3630 题意:给你多个字符串,如果其中任意两个字符串满足一个是另一个的前缀,那么输出NO,否则输出YES 思路:简单的trie树应用,插 ...
- poj 3630 Phone List(字典树)
题目链接: http://poj.org/problem?id=3630 思路分析: 求在字符串中是否存在某个字符串为另一字符串的前缀: 即对于某个字符串而言,其是否为某个字符串的前缀,或存在某个其先 ...
- Poj 2499 Binary Tree(贪心)
题目链接:http://poj.org/problem?id=2499 思路分析:结点向左边移动时结点(a, b)变为( a+b, b),向右边移动时( a, b )变为( a, a + b); 为求 ...
随机推荐
- Linux时间子系统之七:定时器的应用--msleep(),hrtimer_nanosleep()【转】
转自:http://blog.csdn.net/droidphone/article/details/8104433 我们已经在前面几章介绍了低分辨率定时器和高精度定时器的实现原理,内核为了方便其它子 ...
- oracle用plsql查询死锁
1. 点击plsql 工具(tool),点击会话(session) 2.点击锁,可以看到锁的session
- java基础23 Math类和Random类
一.Math数学类 主要是提供很多数学的公式 1.1.Math类的常用方法 abs(int a):绝对值 ceil(double a):向上取整 floor(double a):向下取整 ...
- 网络协议之TCP
前言 近年来,随着信息技术的不断发展,各行各业也掀起了信息化浪潮,为了留住用户和吸引用户,各个企业力求为用户提供更好的信息服务,这也导致WEB性能优化成为了一个热点.据分析,网站速度越快,用户的黏性. ...
- C实现线程池
简介:这里使用linux下的互斥锁和条件变量实现了一个线程池.代码由一个未知作者完成,第二任作者补充优化. 本人仅仅是做了一些注释工作. 代码如下: /*! .h */ #include <st ...
- 虚拟机的安装以及Linux的学习
安装虚拟机 对虚拟机的认识 其实初中的时候我就听说过虚拟机这个名词,当时的我还小,也不知道虚拟机是个什么东西,那时我傻傻的认为虚拟机只不过是电脑中的一个虚拟的计算机,没有什么实在的作用.后来随着大学课 ...
- 手工增加Mapping
[root@es ~]# curl -H "Content-Type:application/json" -XPOST "http://127.0.0.1:9200/t_ ...
- CCF CSP 201403-2 窗口
CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201403-2 窗口 问题描述 在某图形操作系统中,有 N 个窗口,每个窗口都是一个两边与坐标 ...
- 【LOJ】#2046. 「CQOI2016」路由表
题解 题面太长无法阅读系列-- 这里说的选择改变指的是在下面区间里碰上了一个更长的可匹配的地址,如果可匹配但是匹配长度没有当前的值大,那么不算改变 我们建一个可持久化的trie,查询的时候先在前\(a ...
- 【LOJ】 #2025. 「JLOI / SHOI2016」方
题解 有什么LNOI啊,最后都是JLOI罢了 一道非常--懵逼的统计题 当然是容斥,所有的方案 - 至少有一个点坏掉的正方形 + 至少有两个点坏掉的正方形 - 至少有三个点坏掉的正方形 + 至少有四个 ...