| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:……我错了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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator