- 1、本文档共40页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Divide and Conquer Lecture by Hao Wu 一般方法 Master Theorem T(n)=aT(n/b)+f(n) 常见分治法 二分法 三分法 二分搜索 案例1:Babelfish Time Limit: 3000MS Memory Limit: 65536K Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them. Input Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters. Output Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as eh. Sample Input dog ogday cat atcay pig igpay froot ootfray loops oopslay atcay ittenkay oopslay Sample Output cat eh loops 解题思路 二分查找 因为字典的规模达到100,000的规模,使用线性查找时间肯定不行 核心代码 typedef struct{char src[20],tag[20];}Dict; int cmp(Dict *a,Dict *b){ Return strcmp((*a).tag,(*b).tag);} int BS(int b,int e,char *s){ If (b0||e=n||be||b==estrcmp(D[s].tag,s)) Return -1; int m=(s+e)/2; If (strcmp(D[m].tag,s)==0)return m; If (strcmp(D[m].tag,s)0)return BS(m+1,e,s); return BS(b,m-1,s);} 核心代码(续) int main(){ qsort(D,n,sizeof(D[0]),cmp); while(scanf(“%s”,s)!=EOF) printf(“%s\n”,(r=BS(0,n-1,s))==-1?”eh”:D[r]); Return 0;} 案例6:Raising Modulo Numbers Time Limit:1000MS? Memory Limit:30000K Description People are different. Some secretly read magazines full of interesting girls pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical games. Latest marketing research shows, that this market segment was so far underestimated and that there is lack of such games. This kind of game was thus included i
您可能关注的文档
最近下载
- 对照《中国共产党纪律处分条例》排查梳理违纪风险点(共30条,包含产生因素和防范举措).docx VIP
- 初中物理教师招聘选调考试精彩试题.docx
- 房屋租赁合同70582.doc
- 初中物理探究式教学研究结题报告草稿.doc
- 培训机构辅导班兼职教师聘用合同协议.doc
- 2022-2023学年北京市西城区高二下学期期末考试语文试题(解析版).docx
- 舞剧的僭越——作为符号的舞蹈诗剧《只此青绿》.pdf VIP
- DB53/T 2007-2015- 钢筋保护层混凝土垫块质量检测技术规程.pdf
- 初中物理教师招聘选调考试试题(2).doc VIP
- 学前儿童社会教育(学前儿童社会教育活动指导)-国家开放大学电大期末纸考卷考题目答案.pdf
文档评论(0)