欧拉图的遍历 dfs
数据太大 手写dfs
#include<cstdio>
#include<cstring>
const int maxn=1000007;
int stack[maxn],top;
int ans[maxn],at;
int list[maxn];
void search(int v,int m)
{
int w;
while(list[v]<10)
{
w=v*10+list[v];
list[v]++;
stack[top++]=w;
v=w%m;
}
}
int main()
{
int n,m;
while(~scanf("%d",&n),n)
{
if(n==1)
{
puts("0123456789");
continue;
}
memset(list,0,sizeof(list));
top=at=0;
int i,v;
v=0;
for(m=1,i=1;i<n;i++)
{
m*=10;
}
search(v,m);
while(top)
{
v=stack[--top];
ans[at++]=v%10;
search(v/10,m);
}
for(i=1;i<n;i++)
{
putchar('0');
}
while(at)
{
putchar('0'+ans[--at]);
}
puts("");
}
return 0;
}
本文介绍了一种使用深度优先搜索(DFS)手写实现的方法来解决欧拉图的大规模数据遍历问题。通过具体代码示例展示了如何针对特定规模的数据集进行有效的图遍历,并详细解释了关键步骤。
557

被折叠的 条评论
为什么被折叠?



