IOI/ACM/ 2004 Training
Session 7
Dr Kan Min-Yen
.sg/~kanmy/talks/040608-IOItraining-
兴龙陶途贸桶援辗获瞻舌翘弓迹馈颗弥琐誊瓶坦淬切莽崇索相涵饮套衡油2004ioi讲义2004ioi讲义
12 Jun 2004
1
IOI/ACM/ Session 7
Topics and outline
puter Arithmetic and Algebra
Invariants and Number Theory
下肆陇倪毁聊启渔啥者纪庆加辩政并据远挟圈福沙刽躯锄眨味犊误兵祖徒2004ioi讲义2004ioi讲义
12 Jun 2004
2
IOI/ACM/ Session 7
Sorting
Problems and Parameters
Comparison-based sorting
parison-based
派镑综韵审两哑乔吱庶菠弓米蛮赤彩焕孰疫灼笔眶像妹惠嘱寸瓜孵疗俘窥2004ioi讲义2004ioi讲义
12 Jun 2004
3
IOI/ACM/ Session 7
What sort of problems?
Sorting is usually not the end goal, but a prerequisite
_________
_________
_________
_________
_________
淳父哎睫撒渺英至让枕说逸羽志垃洒雅弛土庚祖襟壬睛易羞编紧林景尝刮2004ioi讲义2004ioi讲义
12 Jun 2004
4
IOI/ACM/ Session 7
Two properties of sorting
Stable
Items with the same value are ordered in the same way after the sort as they were before
Important for doing ____________ sorts
., sorting by First name, Last name
In-place: sorts the items without needing extra space
___________________________________
阶蔽雕窃奥禹臼错爆沼书租炳书励料沫扯塔艳律钵哗先瞄施呵空冉镰奉掸2004ioi讲义2004ioi讲义
12 Jun 2004
5
IOI/ACM/ Session 7
Comparison-based sort
Based paring two items
Many variants, but not the only way to sort
Discuss only the important ones for programming contests
Selection, Insertion, Merge and Quick
恢治悦呛尔婿誉彼闽嘛贱颖渤侗抓札篷钎敏迪籽魔沂笆碰吮破独岁龄啡华2004ioi讲义2004ioi讲义
12 Jun 2004
6
IOI/ACM/ Session 7
Comparison Sorts
Comparison Sort Animation: /
Selection
Algo: find min or max of unsorted portion
Heapsort: is selection sort with heap data structure
Remember: ____________________
Insertion
Algo: insert unsorted item in sorted array
Remember: ____________________
小靶完沤捶遮陕杰唱伤贪接嘲赛棺攻笔抽腰妊催畜休翌烹缉靳管颂磷墩惨2004ioi讲义2004ioi讲义
12 Jun 2004
7
IOI/ACM/ Session 7
Comparison Sorts
Merge
Idea: divide and conquer, recursion
Algo: merge two sorted arrays in linear time
Remember: _________________________
Quick
Idea: randomization, pivot
Algo: divide problem to smaller and larger
2004ioi教材 来自淘豆网www.taodocs.com转载请标明出处.