日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

HDOJ 1247 HDU 1247 Hat’s Words ACM 1247 IN HDU

發(fā)布時(shí)間:2023/12/18 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDOJ 1247 HDU 1247 Hat’s Words ACM 1247 IN HDU 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自?______________白白の屋????

?

題目地址 :

?? ? http://acm.hdu.edu.cn/showproblem.php?pid=1247?

題目描述:

Hat’s Words

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1384????Accepted Submission(s): 506


Problem DescriptionA hat’s word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.
You are to find all the hat’s words in a dictionary.

InputStandard input consists of a number of lowercase words, one per line, in alphabetical order. There will be no more than 50,000 words.
Only one case.

OutputYour output should contain all the hat’s words, one per line, in alphabetical order.
Sample Inputa ahat hat hatword hziee word
Sample Outputahat hatword

題目分析 :

??

?? ? ? ?字典樹的題目, 這個(gè)題的方法比較暴力, ?在輸入的時(shí)候?qū)⒚總€(gè)單詞都加入字典樹, ?并用數(shù)組將所有的串都存起來(lái)來(lái).

在輸入完成后, ?對(duì)每個(gè)單詞進(jìn)行拆分, 也就是暴力枚舉單詞不同位置的前后部分, 看在字典樹中是否存在, 存在即輸出.

不過(guò)貌似數(shù)據(jù)比較弱, 說(shuō)是按字典順序輸出, 但其實(shí)他的輸入本就是按字典順序輸入的, 所以將排序也面了 , 呵呵.

?? ?另外,其實(shí)這題用STL 做更簡(jiǎn)單, 當(dāng)然追求效率除外.

trie 代碼:

?/*

MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋

?? ? ? ? ?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 ?代碼 :

?

?/*

MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋

?? ? ? ? ?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;

}


?

?

轉(zhuǎn)載于:https://www.cnblogs.com/MiYu/archive/2010/08/24/1807147.html

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的HDOJ 1247 HDU 1247 Hat’s Words ACM 1247 IN HDU的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 欧美午夜激情影院 | 色a在线 | 国产网站无遮挡 | missav | 免费高清av在线看 | 免费看黄网站在线 | 婷婷二区 | 91麻豆精品国产91久久久无需广告 | 影音先锋成人网 | 一卡二卡三卡视频 | 国产精品美女久久久 | 狼人色综合 | 日韩欧美中文字幕在线播放 | 国产成人精品亚洲男人的天堂 | 亚洲成人av一区二区 | 国产精品无码av在线播放 | 亚洲精品乱码久久久久久久 | 精品人人人人 | 四虎在线视频免费观看 | 天天草天天操 | 天天操婷婷 | 碧蓝之海动漫在线观看免费高清 | 在线不卡毛片 | 久久精品国产亚洲a | 久久9999久久免费精品国产 | 爱爱小视频免费看 | 深夜福利国产精品 | 午夜精品久久久久久99热 | 嫩草大剧院| 久热热 | 亚洲精品免费电影 | 免费在线不卡av | 久久久久久久久久久99 | 一本色道久久亚洲综合精品蜜桃 | 天天摸天天射 | 日韩在线视频一区二区三区 | 午夜免费片 | 黄色大片免费观看 | 99久久婷婷国产综合精品电影 | 亚洲毛片网 | 337p色噜噜 | 日本黄色片在线播放 | 久久网站免费看 | 高清成人免费视频 | 激情久| 911看片| 国产视频一区二区三区在线播放 | 亚洲视频免费观看 | 少妇又紧又深又湿又爽视频 | 无码任你躁久久久久久老妇 | 亚洲av永久无码精品放毛片 | 日韩av色 | 亚洲插| www 在线观看视频 | 色哟哟网站在线观看 | www.四虎在线观看 | av网址观看| 成人av免费看 | 成人在线观看免费视频 | 日韩一区2区 | 亚洲一区二区自偷自拍 | 欧美一区二区三区免费 | 免费在线一级片 | 一级一片免费播放 | √天堂资源地址在线官网 | 国产欧美日韩综合精品一区 | 亚洲欧美日韩国产综合 | 综合久久久久久久 | 日韩精品免费一区二区三区竹菊 | 中文字幕在线观看二区 | 日本乱偷中文字幕 | 青青青草视频在线观看 | 欧美成人一二三 | 国产操片| 国产小视频在线观看免费 | 我要看免费黄色片 | 久久无吗视频 | 久久99精品久久久久久国产越南 | 在线久久| 国产真实夫妇交换视频 | 日本十大三级艳星 | 永久免费看片在线观看 | 亚洲中文字幕无码av永久 | 国产探花在线精品一区二区 | 精品一区二区三区免费毛片 | 在线观看www.| 一区二区三区免费视频观看 | 欧美婷婷 | 91网站免费观看 | 国产欧美一区二区三区在线看蜜臂 | www.国产91 | 国产在线a视频 | 欧美激情影院 | av在线网址大全 | 久久金品 | 九一爱爱| 亚洲av成人精品日韩在线播放 | 亚洲一区二区三区精品视频 | 伦理久久| 日韩片在线观看 |