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

Re:……我错了

Posted by andy_lee at 2008-01-05 21:01:36 on Problem 2513
In Reply To:……我错了 Posted by:xfxyjwf at 2008-01-04 11:51:10
数据确实恶心了点,这个题我用map过了,发现比用字典树慢了10倍,看来真的得慎用map和set
下面这个GetNum的复杂度为O( lg(n) ) 在查找失败时为O( 2*lg(n) )
应该说并不算差,不明白为什么整体会差那么多。

int col_num = 0;
map< string, int > StrIntMap;

int GetNum( char * str )
{
	map< string, int >::iterator it = StrIntMap.find( str );
	if( it == StrIntMap.end() )
	{
		StrIntMap.insert( make_pair( str, col_num ) );
		return col_num++;
	}
	else
	{
		return it->second;
	}
}

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