当前位置:网站首页>Uva11362 phone list solution
Uva11362 phone list solution
2022-07-19 00:56:00 【q779】
UVA11362 Phone List Answer key
Topic link :UVA11362 Phone List
The question : Given n n n No longer than 10 10 10 A string of numbers , Determine whether there are two strings A A A and B B B, Satisfy A A A yes B B B The prefix of , If you have any , Output
NO, If there is no , OutputYES.
In fact, you can build a t r i e \tt{trie} trie The tree then dfs Of
But for convenience , direct sort You can get through it
Time complexity O ( Q n 2 ) O(Qn^2) O(Qn2)
Code :
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <random>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define N (int)(1e4+15)
int Q,n;
string s[N];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("check.in","r",stdin);
// freopen("check.out","w",stdout);
cin >> Q;
while(Q--)
{
cin >> n;
for(int i=1; i<=n; i++)
cin >> s[i];
sort(s+1,s+1+n);
int ok=0;
for(int i=2; i<=n&&!ok; i++)
if(s[i].find(s[i-1])==0)ok=1;
cout << (ok?"NO\n":"YES\n");
}
return 0;
}
Reprint please explain the source
边栏推荐
猜你喜欢
![[untitled]](/img/e7/208612a265e478efc2d9dd5f5d82ac.png)
[untitled]

交换机与路由器技术:热备份路由选择协议HSRP、HSRP和SPVSTP综合实验

Hcia-r & s self use notes (10) VRP foundation, command, remote management

Flowable工作流(flowable 数据库表结构)

Mysql - contrôle de la concurrence Multi - versions (mvcc)

Switch and router technology: Integrated Experiment of hot backup routing protocols HSRP, HSRP and spvstp

Lead friends on the whole network to complete chalk login encryption analysis, and change the way to play again

数据库整理

25篇性能测试文章专题
![[natural language processing] [multimodal] multimodal overview: visual language pre training model](/img/4a/24be4efe9b0347033a9615cf54ceb5.png)
[natural language processing] [multimodal] multimodal overview: visual language pre training model
随机推荐
war或jar使用Resource或ClassPathResource加载classpath下文件失败
Sqli labs less-1 (extractvalue of error injection)
Switch and router technology: link aggregation, spanning tree protocol STP and spanning tree protocol configuration
Mysql—多版本並發控制(MVCC)
Advanced Mathematics - Chapter 8 differential calculus of multivariate functions - extreme and maximum values of multivariate functions
Deep learning paper: lednet: a lightweight encoder decoder network for real-time semantic segmentation and its pytorch implementation
Go 每日一库之 bitset
prometheus+grafana可视化实时jvm监控工具
el-table动态添加可输入行的问题
基于yoloV5的.pt模型转换为.engine模型,并通过Deepstream加速,可多相机实时传输,采用nvidia的Xavier板子(精一)
Rocky基础练习题-find、sed、grep、tar
Leetcode-5 longest palindrome substring
数据库整理
NIO三板斧之Buffer,提升程序运行效率的双刃剑
Hcia-r & s self use notes (10) VRP foundation, command, remote management
深度学习论文: LEDnet: A lightweight encoder-decoder network for real-time semantic segmentation及其PyTorch实现
Lead friends on the whole network to complete chalk login encryption analysis, and change the way to play again
API design principles from the requirements of compiler for instruction set
【clickhouse】周的计算
Mysql—多版本并发控制(MVCC)