Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

放弃了,,,这题怎么做的啊,,,我的map果断tle,,,,难道要写hash,,或者trie,,,然后写一些rb树,avl之类的东西吗?500个句子就tle,,真郁闷,,?扔下我的代码,,谁帮忙看看是不是哪里死循环了??

Posted by yy17yy at 2011-03-02 20:39:25 on Problem 1760
#pragma warning(disable:4786)
#include <iostream>
#include <map>
#include <string>
#include <cstring>
using namespace std;
const int N=1111;
struct node
{
	map<string,int>m;
	char s[11];
}nod[20000];
void dfs(int u,int dep)
{
	for(map<string,int>::iterator i=nod[u].m.begin();i!=nod[u].m.end();i++)
	{
		for(int j=1;j<=dep;j++)
			putchar(' ');
		printf("%s\n",(i->first).c_str());
		dfs(i->second,dep+1);
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	char c[N];
	int i,j,id=0,num[N];
	for(i=1;i<=n;i++)
	{
		scanf("%s",c);
		int end=0;
		num[++end]=0;
		for(j=0;c[j];j++)
			if(c[j]=='\\')
				c[j]=0,num[++end]=j+1;
		if(!nod[0].m.count(c))
			nod[0].m[c]=++id,strcpy(nod[id].s,c);
		int p=nod[0].m[c];
		for(j=2;j<=end;j++)
		{
			if(!nod[p].m.count(c+num[j]))
				nod[p].m[c+num[j]]=++id,strcpy(nod[id].s,c+num[j]);
			p=nod[p].m[c+num[j]];
		}
	}
	dfs(0,0);
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator