社区讨论

求救大佬 为什么本蒟蒻是tle

UVA644Immediate Decodability参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mi7xbyze
此快照首次捕获于
2025/11/21 05:09
4 个月前
此快照最后确认于
2025/11/21 05:09
4 个月前
查看原帖
CPP
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int cnt=0,len,num;
char str[12];
int tree[1000000][11];
bool tail[1000000],ans=false;
inline void clean()
{
	memset(tree,0,sizeof(tree));
	memset(tail,false,sizeof(tail));
	num=0;
	ans=false;
}
bool insert()
{
	int now=0;
	bool res=false;
	for(int i=0;i<len;i++)
	{
		int temp=str[i]-'0';
		if(!tree[now][temp])//new node
			tree[now][temp]=++num;
		else
			if(i==len-1)//never buile new node
				res=true;
		if(tail[now])//include other str 
			res=true;
		now=tree[now][temp];
	}
	tail[now]=true;
	return res;
}
int main()
{
	while(scanf("%s",str)!=EOF)
	{
		len=strlen(str);
		if(len==1&&str[0]=='9')//'9'
		{
			if(ans) printf("Set %d is not immediately decodable\n",++cnt);
			else printf("Set %d is immediately decodable\n",++cnt);
			clean();
		}
		else//except '9'
		if(insert()) ans=true;
	}
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...