MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?nbsp;______________鐧界櫧銇眿
STL 浠g爜濡備笅 : 濂界煭....
/*
MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?______________鐧界櫧銇眿
http://www.cnblog.com/MiYu
Author By : MiYu
Test : 1
Program : 1075
*/
#include <iostream>
#include <string>
#include <map>
using namespace std;
string words,temp;
map < string , string > mp;
int main ()
{
cin >> words;
while ( cin >> words, words != "END" )
{
cin >> temp;
mp[ temp ] = words;
}
cin >> words;
getchar();
while ( getline ( cin, words ) && words != "END" )
{
string out = "";
int len = words.size();
for ( int i = 0; i != len; ++ i )
{
if ( isalpha ( words[i] ) )
{
out += words[i];
}
else
{
if ( mp[out] == "" )
cout << out;
else
cout << mp[out];
cout << words[i];
out = "";
}
}
cout << endl;
}
return 0;
}
MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?nbsp;______________鐧界櫧銇眿
棰樼洰鍦板潃:
http://acm.hdu.edu.cn/showproblem.php?pid=1800
棰樼洰鎻忚堪:
4 10 20 30 04 5 2 3 4 3 4
1 2
棰樼洰鍒嗘瀽:
鐩稿鏉ヨ榪欓鐢ㄥ瓧鍏告爲(wèi)鐨勬晥鐜囨瘮杈冮珮浜?....閬楁喚鐨勬槸鎴戠幇鍦ㄥ彧浼?xì)鍋氫竴浜涘瓧鍏告爲(wèi)鐨?姘撮....瀵瑰瓧鍏告爲(wèi)鐨勭悊瑙g幇鍦ㄨ繕涓嶆槸寰堝ソ......鎵浠?鍛靛懙
榪欓鎴戝氨鐩存帴絳涢夎繃浜?.......
浠g爜濡備笅:
/*
MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?______________鐧界櫧銇眿
http://www.cnblog.com/MiYu
Author By : MiYu
Test : 1
Program : 1800
*/
#include <iostream>
#include <algorithm>
using namespace std;
int num[3002];
bool hash[3002];
bool cmp ( const int &a, const int &b )
{
return a > b;
}
int main ()
{
int N;
while ( scanf ( "%d", &N ) != EOF )
{
memset ( num, 0, 12008 );
memset ( hash, 0, 3002 );
for ( int i = 0; i != N; ++ i )
scanf ( "%d",num + i );
sort ( num, num + N, cmp );
int nCount = 0;
for ( int i = 0; i < N; ++ i )
{
if ( !hash[i] )
{
nCount ++;
int j = i ,k = j+1;
hash[j] = true;
while ( k < N )
{
if ( !hash[k] && num[k] < num[j] )
{
hash[k] = true;
j = k;
}
k++;
}
}
}
printf ( "%d\n",nCount );
}
return 0;
}
MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?nbsp;______________鐧界櫧銇眿
棰樼洰鍦板潃 :
http://acm.hdu.edu.cn/showproblem.php?pid=1247
棰樼洰鎻忚堪:
a ahat hat hatword hziee word
ahat hatword
棰樼洰鍒嗘瀽 :
瀛楀吀鏍?wèi)鐨勯鐩? 榪欎釜棰樼殑鏂規(guī)硶姣旇緝鏆村姏, 鍦ㄨ緭鍏ョ殑鏃跺欏皢姣忎釜鍗曡瘝閮藉姞鍏ュ瓧鍏告爲(wèi), 騫剁敤鏁扮粍灝嗘墍鏈夌殑涓查兘瀛樿搗鏉ユ潵.
鍦ㄨ緭鍏ュ畬鎴愬悗, 瀵規(guī)瘡涓崟璇嶈繘琛屾媶鍒? 涔熷氨鏄毚鍔涙灇涓懼崟璇嶄笉鍚屼綅緗殑鍓嶅悗閮ㄥ垎, 鐪嬪湪瀛楀吀鏍?wèi)涓槸鍚﹀瓨鍦? 瀛樺湪鍗寵緭鍑?
涓嶈繃璨屼技鏁版嵁姣旇緝寮? 璇存槸鎸夊瓧鍏擱『搴忚緭鍑? 浣嗗叾瀹炰粬鐨勮緭鍏ユ湰灝辨槸鎸夊瓧鍏擱『搴忚緭鍏ョ殑, 鎵浠ュ皢鎺掑簭涔熼潰浜?, 鍛靛懙.
鍙﹀,鍏跺疄榪欓鐢⊿TL 鍋氭洿綆鍗? 褰撶劧榪芥眰鏁堢巼闄ゅ.
trie 浠g爜:
/*
MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?______________鐧界櫧銇眿
http://www.cnblog.com/MiYu
Author By : MiYu
Test : 1
Program : 1247
*/
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef struct dictor DIC;
DIC *root = NULL;
struct dictor {
dictor (){ exist = false; memset ( child , 0 , sizeof ( child ) ); }
void insert ( char *ins );
bool find ( const char *ins );
private:
DIC *child[26];
bool exist;
};
void dictor::insert ( char *ins )
{
DIC *cur = root,*now;
int len = strlen ( ins );
for ( int i = 0; i < len; ++ i )
{
if ( cur->child[ ins[i] - 'a' ] != NULL )
{
cur = cur->child[ ins[i] - 'a' ];
}
else
{
now = new DIC;
cur->child[ ins[i] - 'a' ] = now;
cur = now;
}
}
cur->exist = true;
}
bool dictor::find ( const char *ins )
{
DIC *cur = root;
int len = strlen ( ins );
for ( int i = 0; i < len; ++ i )
{
if ( cur->child[ ins[i] - 'a' ] != NULL )
cur = cur->child[ ins[i] - 'a' ];
else
return false;
}
return cur->exist;
}
char words[50050][100];
char s1[100],s2[100];
DIC dict;
int main ()
{
root = &dict;
int n = 0;
while ( scanf ( "%s",words[n] ) != EOF )
{
dict.insert ( words[n++] );
}
for ( int i = 0; i < n; ++ i )
{
int len = strlen ( words[i] );
for ( int j = 1; j < len; ++ j )
{
memset ( s1, 0, sizeof ( s1 ) );
memset ( s2, 0, sizeof ( s2 ) );
strncpy ( s1, words[i], j );
strcpy ( s2, words[i]+j );
if ( dict.find ( s1 ) && dict.find ( s2 ) )
{
printf ( "%s\n", words[i] );
break;
}
}
}
//system ( "pause" );
return 0;
}
STL 浠g爜 :
/*
MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?______________鐧界櫧銇眿
http://www.cnblog.com/MiYu
Author By : MiYu
Test : 2
Program : 1247
*/
#include <iostream>
#include <string>
#include <map>
using namespace std;
map < string , int > mp;
string str[50005];
int main ()
{
int n = 0;
while ( cin >> str[n] ) mp[ str[n++] ] = 1;
for ( int i = 0; i < n; ++ i )
{
unsigned len = str[i].size ();
for ( unsigned j = 1; j < len; ++ j )
{
string s1 ( str[i], 0, j );
string s2 ( str[i], j );
if ( mp[s1] == 1 && mp[s2] == 1 )
{
cout << str[i] << endl;
break;
}
}
}
return 0;
}
MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?nbsp;______________鐧界櫧銇眿
棰樼洰鍦板潃:
http://acm.hdu.edu.cn/showproblem.php?pid=1251
棰樼洰鎻忚堪:
banana band bee absolute acm ba b band abc
2 3 1 0
鍒氬瀛楀吀鏍?,涔熷氨鏄?trie 鏍? 鏁欑▼寰堝鏄撶湅鏄庣櫧, 1251 鏄竴閬撳緢鏄庢樉鐨?妯℃澘棰? 鐪嬭繃 PPT 鍚?鐩存帴鏁蹭唬鐮?1A.
絎竴嬈″仛, 欏轟究浠嬬粛涓?trie鏍?:
瀛楀吀鏍?wèi)锛圱rie錛夋槸涓縐嶇敤浜庡揩閫熷瓧絎︿覆媯绱㈢殑澶氬弶鏍?wèi)缁撴瀯銆傚叾鍘熺悊鏄埄鐢ㄥ瓧絎︿覆鐨勫叕鍏卞墠緙鏉ラ檷浣庢椂絀哄紑閿,浠庤岃揪鍒版彁楂樼▼搴忔晥鐜囩殑鐩殑銆?/p>
銆銆瀹冩湁濡備笅綆鍗曠殑鎬ц川錛?/p>
銆銆銆銆(1) 鏍硅妭鐐逛笉鍖呭惈瀛楃淇℃伅錛?/p>
銆銆銆銆(3) 涓媯祄搴︾殑Trie鎴栬呬負(fù)絀猴紝鎴栬呯敱m媯祄搴︾殑Trie緇勬垚銆?/p>
銆銆 鎼滅儲瀛楀吀欏圭洰鐨勬柟娉曚負(fù)錛?/p>
銆銆銆銆(1) 浠庢牴緇撶偣寮濮嬩竴嬈℃悳绱紱
銆銆銆銆(2) 鍙栧緱瑕佹煡鎵懼叧閿瘝鐨勭涓涓瓧姣嶏紝騫舵牴鎹瀛楁瘝閫夋嫨瀵瑰簲鐨勫瓙鏍?wèi)銆銆銆銆銆銆騫惰漿鍒拌瀛愭爲(wèi)緇х畫榪涜媯绱紱
銆銆銆銆(3) 鍦ㄧ浉搴旂殑瀛愭爲(wèi)涓婏紝鍙栧緱瑕佹煡鎵懼叧閿瘝鐨勭浜屼釜瀛楁瘝錛?/p>
銆銆銆銆銆銆騫惰繘涓姝ラ夋嫨瀵瑰簲鐨勫瓙鏍?wèi)杩涜妫绱€?/p>
銆銆銆銆(4) 榪唬榪囩▼……
銆銆銆銆(5) 鍦ㄦ煇涓粨鐐瑰錛屽叧閿瘝鐨勬墍鏈夊瓧姣嶅凡琚彇鍑猴紝鍒欒鍙?/p>
銆銆銆銆銆銆闄勫湪璇ョ粨鐐逛笂鐨勪俊鎭紝鍗沖畬鎴愭煡鎵俱?/span>
浠g爜濡備笅 :
褰撶劧涔熷彲浠ユ嬁鏉ュ仛妯℃澘 ,
/*
MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?______________鐧界櫧銇眿
http://www.cnblog.com/MiYu
Author By : MiYu
Test : 1
Program : 1251
*/
#include <iostream>
using namespace std;
typedef struct dict DIC;
struct dict {
dict (){ n = 0; memset ( child , 0 , sizeof ( child ) ); }
void insert ( char *ins )
{
DIC *cur = this,*now;
int len = strlen ( ins );
if ( len == 0 ) return ;
for ( int i = 0; i != len; ++ i )
{
if ( cur->child[ ins[i] - 'a' ] != NULL )
{
cur = cur->child[ ins[i] - 'a' ];
cur->n ++;
}
else
{
now = new DIC;
cur->child[ ins[i] - 'a' ] = now;
now->n ++;
cur = now;
}
}
}
int find ( char *ins )
{
DIC *cur = this;
int len = strlen ( ins );
if ( 0 == len ) return 0;
for ( int i = 0; i != len; ++ i )
{
if ( cur->child[ ins[i] - 'a' ] != NULL )
cur = cur->child[ ins[i] - 'a' ];
else
return 0;
}
return cur->n;
}
private:
DIC *child[26];
int n;
};
char word[11];
int main ()
{
DIC dict;
while ( gets ( word ), strcmp ( word, "") != 0 )
dict.insert ( word );
char qur[11];
while ( scanf ( "%s",qur ) != EOF )
{
printf ( "%d\n",dict.find ( qur ) );
}
return 0;
}