1. Trang chủ
  2. » Giáo án - Bài giảng

data structure practice for collegiate programming contests and education wu wang 2016 02 04 Cấu trúc dữ liệu và giải thuật

508 30 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 508
Dung lượng 12,44 MB

Nội dung

Computer Science • Fundamental programming skills • Experiments for linear lists • Experiments for trees • Experiments for graphs Each chapter contains a set of problems and includes hints The book also provides test data for most problems as well as sources and IDs for online judgments that help with improving programming skills Introducing a multi-options model and considerations of context, Data Structure Practice for Collegiate Programming Contests and Education encourages students to think creatively in solving programming problems By taking readers through practical contest problems from analysis to implementation, it provides a complete source for enhancing understanding and polishing skills in programming K22004 an informa business www.crcpress.com 6000 Broken Sound Parkway, NW Suite 300, Boca Raton, FL 33487 711 Third Avenue New York, NY 10017 Park Square, Milton Park Abingdon, Oxon OX14 4RN, UK ISBN: 978-1-4822-1539-7 Data Structure Practice Based on successful experiences in many world-level contests, the book includes 204 typical problems and detailed analyses selected from the ACM International Collegiate Programming Contest and other major programming contests since 1990 It is divided into four sections that focus on: Wu Wang Combining knowledge with strategies, Data Structure Practice for Collegiate Programming Contests and Education presents the first comprehensive book on data structure in programming contests This book is designed for training collegiate programming contest teams in the nuances of data structures and for helping college students in computer-related majors to gain deeper understanding of data structure Data Structure Practice for Collegiate Programming Contests and Education Yonghui Wu and Jiande Wang 90000 781482 215397 w w w.crcpress.com K22004 cvr mech.indd 12/9/15 9:01 AM CuuDuongThanCong.com Data Structure Practice for Collegiate Programming Contests and Education CuuDuongThanCong.com CuuDuongThanCong.com Data Structure Practice for Collegiate Programming Contests and Education Yonghui Wu and Jiande Wang CuuDuongThanCong.com Published with arrangement with the original publisher, Beijing Huazhang Graphics and Information Company CRC Press Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300 Boca Raton, FL 33487-2742 © 2016 by Taylor & Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group, an Informa business No claim to original U.S Government works Version Date: 20160126 International Standard Book Number-13: 978-1-4822-1540-3 (eBook - PDF) This book contains information obtained from authentic and highly regarded sources Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint Except as permitted under U.S Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers For permission to photocopy or use material electronically from this work, please access www.copyright.com (http:// www.copyright.com/) or contact the Copyright Clearance Center, Inc (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400 CCC is a not-for-profit organization that provides licenses and registration for a variety of users For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com and the CRC Press Web site at http://www.crcpress.com CuuDuongThanCong.com Contents Preface xiii Authors xv Section I  FUNDAMENTAL PROGRAMMING SKILLS Practice for Simple Computing Improving Programming Style 1.1.1 Financial Management 1.2 Multiple Test Cases 1.2.1 Doubles 1.2.2 Sum of Consecutive Prime Numbers 1.3 Precision of Real Numbers 1.3.1 I Think I Need a Houseboat 1.4 Improving Time Complexity by Dichotomy 11 1.4.1 Hangover 12 1.4.2 Humidex 14 1.5 Problems 17 1.5.1 Sum 17 1.5.2 Specialized Four-Digit Numbers .17 1.5.3 Quicksum 18 1.5.4 A Contesting Decision 19 1.5.5 Dirichlet’s Theorem on Arithmetic Progressions .21 1.5.6 The Circumference of the Circle 22 1.5.7 Vertical Histogram 26 1.5.8 Ugly Numbers 27 1.5.9 Number Sequence 28 1.1 Simple Simulation .29 2.1 2.2 2.3 Simulation of Direct Statement 29 2.1.1 Speed Limit 29 2.1.2 Ride to School 31 Simulation by Sieve Method 33 2.2.1 Self-Numbers 33 Construction Simulation .35 2.3.1 Bee 35 v CuuDuongThanCong.com vi  ◾ Contents 2.4 Problems 37 2.4.1 Gold Coins 37 2.4.2 The 3n + 1 Problem 38 2.4.3 Pascal Library 39 2.4.4 Calendar 41 2.4.5 Manager 42 Simple Recursion .45 3.1 3.2 Calculation of Recursive Functions 46 Solving Problems by Recursive Algorithms 47 3.2.1 Red and Black 48 3.3 Solving Recursive Datum 51 3.3.1 Symmetric Order 51 3.4 Problems 54 3.4.1 Fractal 54 3.4.2 Sticks 56 SUMMARY OF SECTION I Section II EXPERIMENTS FOR LINEAR LISTS Linear Lists Accessed Directly 65 4.1 Application of Arrays 1: Calculation of Dates 65 4.1.1 Calendar 66 4.1.2 What Day Is It? 68 4.2 Application of Arrays 2: Calculation of High-Precision Numbers 72 4.2.1 Adding Reversed Numbers .74 4.2.2 Very Easy! 77 4.3 Application of Arrays 3: Representation and Computation of Polynomials 80 4.3.1 Polynomial Showdown 81 4.3.2 Modular Multiplication of Polynomials 83 4.4 Application of Arrays 4: Calculation of Numerical Matrices 86 4.4.1 Error Correction 87 4.4.2 Matrix Chain Multiplication 89 4.5 Character Strings 1: Storage Structure of Character Strings 93 4.5.1 TEX Quotes 93 4.6 Character Strings 2: Pattern Matching of Character Strings 94 4.6.1 Blue Jeans 95 4.6.2 Oulipo 99 4.7 Problems 101 4.7.1 Moscow Time 101 4.7.2 Double Time 104 4.7.3 Maya Calendar .105 4.7.4 Time Zones .107 4.7.5 Polynomial Remains .109 4.7.6 Factoring a Polynomial 111 4.7.7 What’s Cryptanalysis? .112 CuuDuongThanCong.com Contents  ◾  vii 4.7.8 Run-Length Encoding 113 4.7.9 Zipper .114 4.7.10 Anagram Groups 115 4.7.11 English Number Translator 117 4.7.12 Message Decowding .118 4.7.13 Common Permutation 119 4.7.14 Human Gene Functions 120 4.7.15 Palindrome 122 4.7.16 Power Strings 123 4.7.17 Period 123 4.7.18 Seek the Name, Seek the Fame 124 4.7.19 Excuses, Excuses! 125 4.7.20 Product 128 4.7.21 Expression Evaluator 128 4.7.22 Integer Inquiry 129 4.7.23 Super-Long Sums 130 4.7.24 Exponentiation .131 4.7.25 Number Base Conversion .132 4.7.26 Super-Long Sums 134 4.7.27 Simple Arithmetics 134 4.7.28 ab – ba 136 4.7.29 Fibonacci Number 137 4.7.30 How Many Fibs 138 4.7.31 Heritage 138 Applications of Linear Lists for Sequential Access 141 5.1 Application of Sequence Lists 142 5.1.1 Children 142 5.1.2 The Dole Queue 143 5.2 Application of Stacks 145 5.2.1 Rails 145 5.2.2 Boolean Expressions 151 5.3 Application of Queues 154 5.3.1 A Stack or a Queue? 154 5.3.2 Team Queue 156 5.3.3 Printer Queue 161 5.4 Problems 163 5.4.1 Roman Roulette 163 5.4.2 M*A*S*H 164 5.4.3 Joseph .165 5.4.4 City Skyline 166 5.4.5 Anagrams by Stack 168 Generalized List Using Indexes .171 6.1 Solving Problems Using Dictionaries 171 6.1.1 References .172 6.1.2 Babelfish 176 CuuDuongThanCong.com viii  ◾ Contents 6.2 Solving Problems Using a Hash Table and the Hash Method 179 6.2.1 10-20-30 179 6.3 Problems 185 6.3.1 Spell Checker 185 6.3.2 Snowflake Snow Snowflakes 188 6.3.3 Equations 188 Sort of Linear Lists 191 7.1 Using Sort Function in STL 191 7.1.1 Hardwood Species 191 7.1.2 Who’s in the Middle? 194 7.1.3 ACM Rank Table 195 7.2 Using Sort Algorithms 197 7.2.1 Flip Sort 197 7.2.2 Ultra-Quicksort 199 7.3 Problems 201 7.3.1 Ananagrams 201 7.3.2 Grandpa Is Famous 202 7.3.3 Word Amalgamation 203 7.3.4 Questions and Answers 205 7.3.5 Find the Clones 206 7.3.6 487-3279 207 7.3.7 Holiday Hotel 209 7.3.8 Train Swapping .210 7.3.9 Unix ls 211 7.3.10 Children’s Game .213 7.3.11 DNA Sorting 214 7.3.12 Exact Sum .215 7.3.13 Shellsort 216 7.3.14 Tell Me the Frequencies! 219 7.3.15 Anagrams (II) 219 7.3.16 Flooded! 221 7.3.17 Football Sort 222 7.3.18 Trees 225 SUMMARY OF SECTION II Section III EXPERIMENTS FOR TREES Programming by Tree Structure .231 8.1 8.2 8.3 Solving Hierarchical Problems by Tree Traversal 231 8.1.1 Nearest Common Ancestor 232 8.1.2 Hire and Fire 236 Union–Find Sets Supported by Tree Structure 241 8.2.1 Find Them, Catch Them 243 8.2.2 Cube Stacking 246 Calculation of Sum of Weights of Subtrees by Binary Indexed Trees 248 8.3.1 Apple Tree .250 CuuDuongThanCong.com Contents  ◾  ix 8.4 Problems 254 8.4.1 Friends 254 8.4.2 Wireless Network 255 8.4.3 War 257 8.4.4 Ubiquitous Religions 259 8.4.5 Network Connections 260 8.4.6 Building Bridges .261 8.4.7 Family Tree 264 8.4.8 Directory Listing 267 8.4.9 Closest Common Ancestors 268 8.4.10 Who’s the Boss? 269 8.4.11 Disk Tree 272 8.4.12 Marbles on a Tree 273 8.4.13 This Sentence Is False 275 Applications of Binary Trees 281 9.1 Converting Ordered Trees to Binary Trees 281 9.1.1 Tree Grafting 282 9.2 Paths of Binary Trees 285 9.2.1 Binary Tree 285 9.3 Traversal of Binary Trees 287 9.3.1 Tree Recovery 288 9.4 Problems 291 9.4.1 Tree Summing 291 9.4.2 Trees Made to Order 292 10 Applications of Classical Trees 295 10.1 Binary Search Trees 295 10.1.1 BST 296 10.1.2 Falling Leaves 297 10.2 Binary Heaps .301 10.2.1 Windows Message Queue 303 10.2.2 Binary Search Heap Construction 306 10.2.3 Decode the Tree 309 10.3 Huffman Trees 311 10.3.1 Fence Repair 312 10.4 Problems 314 10.4.1 Cartesian Tree 314 10.4.2 Argus 316 10.4.3 Black Box 317 10.4.4 Heap .319 10.4.5 How Many Trees? 320 10.4.6 The Number of the Same BST 322 10.4.7 The Kth BST 325 10.4.8 The Prufer Code 330 10.4.9 Code the Tree 331 SUMMARY OF SECTION III CuuDuongThanCong.com ... original U.S Government works Version Date: 20160126 International Standard Book Number-13: 97 8-1 -4 82 2-1 54 0-3 (eBook - PDF) This book contains information obtained from authentic and highly regarded... the Copyright Clearance Center, Inc (CCC), 222 Rosewood Drive, Danvers, MA 01923, 97 8-7 5 0-8 400 CCC is a not-for-profit organization that provides licenses and registration for a variety of users... more job descriptions, separated by a line containing only the end-of-line marker The input file ends with the standard end-of-file marker For each day, your program determines whether an allocation

Ngày đăng: 30/08/2020, 16:46

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN