poj3630

 

#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
struct node
{
	bool color;
	node *next[10];
	node()
	{
		color=false;
		memset(next,NULL,sizeof(next));
	}
};node tre[1000050];//动态创建会超时

int num;
bool insert(node *root,char *str)//可行时反回true
{
	int data,i;
	bool flg1;//假设可行
	bool flg2;//假设不可行
	node *p=root;
	flg1=true;flg2=false;
	for (i=0;i<strlen(str);i++)
	{
		data=str[i]-'0';
		if (p->next[data]==NULL)
		{
			p->next[data]=&tre[num++];flg2=true;
		}
		if (p->color!=true)
		{
			;
		} 
		else
		{
			flg1=false;
		}
		p=p->next[data];
	}
	p->color=true;
	return flg1&flg2;
}
int main()
{
	int i,t,n;
	char a[10];
	bool flg;
	cin>>t;
	while(t--)
	{
		flg=true;num=1;//假设可行
		cin>>n;
		for (i=0;i<n;i++)
		{
			scanf("%s",a);
			if (flg&&insert(&tre[0],a))
			{
				;
			} 
			else
			{
				flg=false;
			}
		}
		if (flg)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}

		for (i=0;i<=num;i++)
		{
			tre[i].color=false;
			memset(tre[i].next,NULL,sizeof(tre[i].next));
		}
	}
	return 0;
}

转载于:https://www.cnblogs.com/qijinbiao/archive/2011/09/19/2181744.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值