字符串-Trie树-入门-PhoneList

多组数据的题虽然已经得到答案了一定还是要把本组数据的输入给读完。。。。不然就死定了

#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,r,l) for(int i=(r);i>=(l);i--)
#define random(l,r) ((l)+rand()%((r)-(l)+1))
#define myset(a,v) memset((a),(v),sizeof((a)));
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
const int inf=1e9+10;
const double eps=1e-6;
int t,n,ch[100010][10],num;
bool tail[1000010];
char s[1000];
bool insert(char s[],int len){
	int u=0;
	rep(i,0,len-1){
		int c=s[i]-'0';
		if(!ch[u][c]) ch[u][c]=++num;
		else if (tail[ch[u][c]]) return true;
		u=ch[u][c];
	}
	rep(i,0,9) if(ch[u][i]) return true;
	tail[u]=true;
	return false;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>t;
	while(t--){
		bool ans=false;
		num=0; memset(ch,0,sizeof(ch)); memset(tail,0,sizeof(tail));
		cin>>n;
		while(n--){
			cin>>s;
			if(insert(s,strlen(s))) ans=true;
		}
		if(ans) cout<<"NO"<<endl; else cout<<"YES"<<endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值