[A] The Earth is Flat!

Similar documents
12 Abstract Data Types

COMP3121/3821/9101/ s1 Assignment 1

Data Structure. IBPS SO (IT- Officer) Exam 2017

Unit 8: Analysis of Algorithms 1: Searching

XVIII Open Cup named after E.V. Pankratiev Stage 1: Grand Prix of Romania, Sunday, September 17, 2017

III Data Structures. Dynamic sets

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

( D. Θ n. ( ) f n ( ) D. Ο%

International Mathematics TOURNAMENT OF THE TOWNS. Junior A-Level Solutions Fall 2013

DDS Dynamic Search Trees

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

Graph and Digraph Glossary

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Name CPTR246 Spring '17 (100 total points) Exam 3

INSTITUTE OF AERONAUTICAL ENGINEERING

Algorithms and Data Structures

Problem A - Complete the sequence

(Refer Slide Time: 00:02:00)

Cpt S 122 Data Structures. Data Structures Trees

Data Structures Question Bank Multiple Choice

TI-89 Calculator Workshop #1 The Basics

DATA STRUCTURE AND ALGORITHM USING PYTHON

COS 226 Midterm Exam, Spring 2009

S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani 165

Solutions to Problem Set 1

Indexing and Hashing

A Different Content and Scope for School Arithmetic

3. Fundamental Data Structures

CSCE 2014 Final Exam Spring Version A

2013 Four-by-Four Competition Thursday, January 31st, Round Four-by-Four Competition Thursday, January 31st, 2013.

Summer Final Exam Review Session August 5, 2009

UNC Charlotte 2004 Comprehensive

THE VARIABLE LIST Sort the Variable List Create New Variables Copy Variables Define Value Labels... 4

Unit 1, Lesson 1: Moving in the Plane

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

A Bullseye. Problem. Output. For each dataset, print a line of the form: SCORE: N to M, PLAYER P WINS. Or: SCORE: N to M, TIE.

Problem A. Interactive Smiley Face

CS 206 Introduction to Computer Science II

may be sent to:

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Introduction. for large input, even access time may be prohibitive we need data structures that exhibit times closer to O(log N) binary search tree

CHENNAI MATHEMATICAL INSTITUTE M.Sc. / Ph.D. Programme in Computer Science


CSE 241 Class 17. Jeremy Buhler. October 28, Ordered collections supported both, plus total ordering operations (pred and succ)

13. [Exploring Number]

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

CS301 - Data Structures Glossary By

Basic Definitions and Concepts Complement to the Prologue and to Chapter 1, Respecting the Rules

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

Fall 2018 #12 Geometry. A. View Angle. 2 seconds, 256 megabytes

Compression. storage medium/ communications network. For the purpose of this lecture, we observe the following constraints:

2.2 Set Operations. Introduction DEFINITION 1. EXAMPLE 1 The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is, EXAMPLE 2

CS171 Final Practice Exam

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

Chapter 11: Indexing and Hashing

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Analysis of Algorithms

Module 2: NETWORKS AND DECISION MATHEMATICS

Fourth Grade Mathematics Vocabulary. Created by Carrie Schoenfelder Staff Development Teacher Strawberry Knoll Elementary School

PA3 Design Specification

1. One-third of 105 is the same as seven-sixths of what number? 1.

Chapter 1. Math review. 1.1 Some sets

CS521 \ Notes for the Final Exam

CSE 417 Dynamic Programming (pt 4) Sub-problems on Trees

ACM-ICPC Indonesia National Contest Problem A. The Best Team. Time Limit: 2s

Further Mathematics 2016 Module 2: NETWORKS AND DECISION MATHEMATICS Chapter 9 Undirected Graphs and Networks

JME Language Reference Manual

Stacks, Queues and Hierarchical Collections

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Data Structure and Algorithm Midterm Reference Solution TA

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

Computer Science E-22 Practice Final Exam

Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103. Chapter 2. Sets

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

We assume uniform hashing (UH):

CHAPTER 4: MICROSOFT OFFICE: EXCEL 2010

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

1. Alicia tosses 3 fair coins. What is the probability that she gets at 1. least 1 head? Express your answer as a common fraction.

[ DATA STRUCTURES ] Fig. (1) : A Tree

Aston Hall s A-Z of mathematical terms

Module 2: Classical Algorithm Design Techniques

( ) n 3. n 2 ( ) D. Ο

where each number (after the first two 1 s) is the sum of the previous two numbers.

Lecture 5: Suffix Trees

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

B-Trees and External Memory

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

COS 226 Algorithms and Data Structures Fall Midterm

So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees.

Problems for JOI The 5th Japanese Olympiad in Informatics

Postfix (and prefix) notation

Chapter 12: Indexing and Hashing. Basic Concepts

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

Transcription:

[A] The Earth is Flat! flat.(c cpp java) flat.in Gold Consider the following language: expression = { c where c is a single, lower-case letter ( e 1 e 2 e t n ) zero or more expressions followed by a natural number The left column of the table below includes sample expressions of this language. Now the flattening of an expression is defined as follows: A single letter is flattened to itself. An expression of the form ( e 1 e 2 e t n ) is flattened by concatenating n copies of the concatenation of the flattening of e i. In other words, if f(e) is the flattening of e, and + symbolizes concatenation, then f( (e 1 e 2 e t n) ) is: f(e 1 )+f(e 2 )+ + f(e t ) }{{} once + twice {}}{ f(e 1 )+f(e 2 )+ + f(e t ) + + f(e 1 )+f(e 2 )+ + f(e t ) }{{} the n th time The following tables show some sample expressions and the result of flattening each. Write a program to flatten a given expression. expression flattened expression w w (c 4) cccc (a (b c 2) 3) abcbcabcbcabcbc Your program will be tested on one or more test cases. Each test case is made of one correctly formed expression written on a separate line. A $ character identifies the end of line. The last line of the input, which is not part of the test cases, contains a $ by itself (possibly with leading and/or trailing white spaces). Every expression in the input is grammatically correct according to the grammar specified above. Note that an expression may contain leading, trailing, and/or embedded spaces. Such spaces should be ignored. Letters and numbers are separated from each other by at least one space character. For each test case expression, write its flattening on a separate line. There should be no spaces (other than newlines) in the output. Page 1 of 16

w$ (c 4)$ (a (b c 2) 3)$ $ w cccc abcbcabcbcabcbc flat.in A. The Earth is Flat! Page 2 of 16

[B] The Double HeLiX helix.(c cpp java) helix.in Green Two finite, strictly increasing, integer sequences are given. Any common integer between the two sequences constitute an intersection point. Take for example the following two sequences where intersection points are printedinbold: First= 3 5 7 9 20 25 30 40 55 56 57 60 62 Second= 1 4 7 11 14 25 44 47 55 57 100 You can walk over these two sequences in the following way: 1. You may start at the beginning of any of the two sequences. Now start moving forward. 2. At each intersection point, you have the choice of either continuing with the same sequence you re currently on, or switching to the other sequence. The objective is finding a path that produces the maximum sum of data you walked over. In the above example, the largest possible sum is 450 which is the result of adding 3, 5, 7, 9, 20, 25, 44, 47, 55, 56, 57, 60, and 62. Your program will be tested on a number of test cases. Each test case will be specified on two separate lines. Each line denotes a sequence and is specified using the following format: n v 1 v 2... v n Where n is the length of the sequence and v i is the ith element in that sequence. Each sequence will have at least one element but no more than 10,000. All elements are between -10,000 and 10,000 (inclusive). The last line of the input includes a single zero, which is not part of the test cases. For each test case, write on a separate line, the largest possible sum that can be produced. Page 3 of 16

helix.in 13 3 5 7 9 20 25 30 40 55 56 57 60 62 11 1 4 7 11 14 25 44 47 55 57 100 4-5 100 1000 1005 3-12 1000 1001 0 450 2100 B.TheDoubleHeLiX Page 4 of 16

[C] Alpha of Degree k alpha.(c cpp java) alpha.in Pink Given two strings s and t, we ll say that the relation alpha of degree k holds between s and t, written as (s αk t), iff there exists a suffix of s with a minimum length of k characters which is also a prefix of t. Note that the alpha relation is not defined for k =0. For example, the word "telnet" is α 3 to "network" while "block" is α 4 (and α 3,andα 2,and α 1 ) related to "locker". An α k chain of length L (where L>0) from word s to word t is a list of L +1wordswheres is the first word, t is the last word, and an α k relation holds between each two consecutive words. For example, here s an α 2 chain of length 4 between "cartoon" and "manual". cartoon α2 one α2 new α2 newsman α2 manual Given a dictionary of words C, two words s and t (taken from the dictionary), and two integers k and L, write a program that determines if there is an α k chain between s and t where the chain s length doesn t exceed L and all words in the chain are from C. Your program will be tested on one or more test cases. The first line of the input specifies a single integer D which represents the number of test cases. Each test case specifies a dictionary of words and a number of queries on that dictionary. The first line of each test case specifies two integers W and Q where W is the number of words in this test case s dictionary and Q is the number queries to be performed on that dictionary. Note that 0 <W <50, 000 and 0 <Q<100. The dictionary is listed starting at line 2 of each test case, one word on each line, all words are composed of lower case letters, there are no duplicates, no spaces, and no word is longer than 64 characters. Following the dictionary, Q queries are specified. Each query is specified on a separate line by specifying two strings s and t and two integers k and L. For each query, determine if, using words found in the dictionary, there is an α k chain from s to t whose length doesn t exceed L. For each query, write the result on a separate line. If there is no chain that satisfies the given constrains, your program should print: a.b none where a is the test case number (starting at 1,) and b is the query number within this test case (again starting at 1.) (continued on next page) Page 5 of 16

If, however, there is a chain, your program should print the following: a.b c word-1 word-2... word-n Where a, b are as described previously, c is the length of the chain. word-1, word-2,... word-n is the chain, where each two consecutive words are separated by a single space. If there are more than one solution for a query, just print anyone of them. 2 8 3 news perusal symbolic newspaper salon longstreet cartoon streetcar news cartoon 3 8 news cartoon 3 4 news cartoon 1 4 2 2 link blink blink link 3 10 link blink 2 100 alpha.in 1.1 6 news newspaper perusal salon longstreet streetcar cartoon 1.2 none 1.3 4 news salon longstreet streetcar cartoon 2.1 1 blink link 2.2 none C. Alpha of Degree k Page 6 of 16

[D] Sort that Queue queue.(c cpp java) queue.in Silver Given a queue Q, astacka, andastackb, and the following operations: QA(n): dequeue an item from Q, pushing it on A; repeat n times QB(n): dequeue an item from Q, pushing it on B; repeat n times QQ(n): dequeue an item from Q, enqueue it again in Q; repeat n times AQ(n): popanitemfroma, enqueue it in Q; repeat n times BQ(n): popanitemfromb, enqueue it in Q; repeat n times AB(n): popanitemfroma, push it on B; repeat n times BA(n): popanitemfromb, push it on A; repeat n times. Note that each of the above is considered a single operation, regardless of the value of n. Now assume that the queue is already populated with numbers and that both stacks are empty, what is the minimum number of operations needed to have the same numbers in the queue but sorted in an ascending order? (smallest in front.) For example, the queue (4 3 1 2 0) where 4 is at the front, can be sorted in three steps as follows: QA(2), QQ(2), thenaq(2). Thequeue(541320) canbesortedinfouroperationsas follows: QB(2), QQ(1), QB(2), BQ(4). Write a program that determines the minimum number of operations needed to sort a given queue. Your program will be tested on a number of test cases. Each test case is specified on a single line. Each test case is made of N + 1 integers. The first integer specifies N which is the number of elements in the queue. A queue of N elements will have in it the integers from 0 to N 1in some random order. The integers in the queue are specified from the front of the queue to the back. No queue will have more than 10 elements. The end of the test cases is identified with an input line that contains a single integer N =0 (which is not part of the test cases.) For each test case, write the result on a separate line. queue.in 5 4 3 1 2 0 6 5 4 1 3 2 0 0 3 4 Page 7 of 16

[E] Still Johnny Can t Add add.(c cpp java) add.in Red One way for young children in elementary schools to practice addition is to make them write down an addition table. An addition table of size N is an (N +1) (N + 1) square matrix, where the top row and + 3-2 5 the left column are labeled with some random integers, (except for their 1 4-1 6 intersection cell where we normally put the plus sign.) The child s task is 4 7 2 9 now to put in each cell the result of adding the label of the row, and the label of the column. For example, the table on the right is an addition table of size 3. -2 1-4 3 Once students grow up and enter intermediate-level schools, we can give them the opposite. Give them an N N table, and let them decide how to add labels for it to be a valid addition table (if it is indeed an addition table.) Given an N N table, which does not include any labels, your job is to decide whether it is possible to properly label it or not. We re not interested in the labels themselves, just decide if it is an addition table or not. For example, the 2 2 table on the left is not an addition table, while the one on the right is. 1 4 3 5 3 6 2 5 Your program will be tested on one or more test cases. The first line in the input is an integer D representing the number of cases. The first line of each test case is an integer N, wheren 10, representing the size of the table. Following that, there will be N lines, each with N integers representing the N N table in a row-major format. Each number in the table is between -10,000 and 10,000 (inclusive). For each test case, output the result on a single line using the following format: k. result Where k is the test case number (starting at 1,) and result is "YES" if the test case is an addition table, or "NO" if it s not. Page 8 of 16

3 3 4-1 6 7 2 9 1-4 3 2 1 4 3 5 2 3 6 2 5 add.in 1. YES 2. NO 3. YES E. Still Johnny Can t Add Page 9 of 16

[F] Newton s Apple newton.(c cpp java) newton.in Purple Two binary trees (called A and B) areequivalent if and only if one of the following two conditions holds: 1. Both trees are empty. Or, 2. The root nodes of both trees are equal, and either: (a) the left subtree of A is equivalent to the left subtree of B, and the right subtree of A is equivalent to the right subtree of B. Or, (b) the left subtree of A is equivalent to the right subtree of B, and the right subtree of A is equivalent to the left subtree of B. For example, the three trees on the left of the following figure are all equivalent to each other but none is equivalent to the right-most tree. A A A A F B B F B F B F G C D C D G D C G C D G E E E E Write a program that determines if two given binary trees are equivalent or not. Your program will be tested on a number of test cases. The first line of the input contains an integer D which represents the number of test cases. Each test case is specified on two lines. The first line specifies the first tree, with the second tree specified on the second line. Each tree is specified using a left-to-right postfix notation where each empty subtree is explicitly specified using the keyword nil. All data in the tree are upper-case letters. The end of the line is specified using the keyword end. For example, the tree on the left of the figure is specified as: nil nil nil G F nil nil C nil nil E nil D B A end For each test case, print on a separate line, the word "true" if the two trees are equivalent. Otherwise print "false". Page 10 of 16

The two test cases in the following sample I/O represent the four trees drawn on the previous page (from left to right) newton.in 2 nil nil nil G F nil nil C nil nil E nil D B A end nil nil C nil nil E nil D B nil nil G nil F A end nil nil nil E D nil nil C B nil nil nil G F A end nil nil nil E C nil nil D B nil nil nil G F A end true false F. Newton s Apple Page 11 of 16

[G] The Euclidian Clock clock.(c cpp java) clock.in Yellow Consider a classical 2-arm 12-hour clock. Now imagine a really precise one. One that can indicate the time in hours, minutes, seconds, and hundredths of a second. Such clock can specify the time between 0:0:0.00 and 11:59:59.99 inclusive. (We ll use the format hour:minute:second.hundredths) to write the time displayed on such clock. Now, you are given two identical clocks of this type, each of them showing some time where the first is strictly before the second. You also know the radius of the clock face. We re interested in computing the area of the clock face determined by the two small (hour) clock-arms on the two clocks. The area starts from the position of the first hour clock-arm and continues in the clockwise way till the position of the second hour clock-arm. Your program will be tested on one or more test cases. The first line in the input specifies a single integer D representing the number of test cases. The first line will be followed by D test cases, where each case is specified on three lines. The first line in a test case specifies four integers denoting the time on the first clock using the following format: H M S U with H for hours, M for minutes, S for seconds, and U for hundredth of a second. Note that 0 H<12, 0 M<60, 0 S<60, and 0 U<100. The second line of a test case specifies the time on the second clock, using thesameformatasthefirst. The third line specifies a real number denoting the radius of the clock. The maximum for the radius is 10,000. For each test case, output the result on a single line using the following format: k. f Where k is the test case number (starting at 1,) and f is the answer, rounded to three decimal places. Page 12 of 16

2 4 10 20 55 8 30 5 10 20.5 3 58 58 44 10 10 7 22 22.25 clock.in 1. 476.286 2. 801.720 G. The Euclidian Clock Page 13 of 16

[H] Chop Ahoy! Revisited! chop.(c cpp java) chop.in Cyan (light blue) Given a non-empty string composed of digits only, we may group these digits into sub-groups (but maintaining their original order) if, for every sub-group but the last one, the sum of the digits in a sub-group is less than or equal to the sum of the digits in the sub-group immediately on its right. Needless to say, each digit will be in exactly one sub-group. For example, the string 635 can only be grouped in one sub-group [635] or in two sub-groups as follows: [6-35] (since 6 < 8.) Another example is the string 1117 which can be grouped in one sub-group [1117] or as in the following: [1-117], [1-1-17], [1-11-7], [1-1-1-7], [11-17], and[111-7] but not any more, hence the total number of possibilities is 7. Write a program that computes the total number of possibilities of such groupings for a given string of digits. Your program will be tested on a number of test cases. Each test case is specified on a separate line. Each line contains a single string no longer than 25, and is made of decimal digits only. Theendofthetestcasesisidentifiedbyalinemadeoftheword"bye" (without the quotes.) Such line is not part of the test cases. For each test case, write the result using the following format: k. n where k is the test case number (starting at 1,) and n is the result of this test case. 635 1117 9876 bye 1. 2 2. 7 3. 2 chop.in Page 14 of 16

[I] What s your Logo? logo.(c cpp java) logo.in Black Imagine a 2D diagram drawn in the following way: Starting at the origin, you re given a sequence of letters which is entirely made of the following four letters U, D, L, and R. A U is an instruction for you to move one unit upward and drawing a segment at the same time. Similarly, D is for moving down, L for left, and R for right. For example, figure (a) is drawn by giving the sequence UURDLL while figure (b) is the result of UURRRDLLLLUURRRDDD (in both figures, the starting point is identified by a small circle.) While segments are allowed to intersect, they re not allowed to overlap. In other words, any two segments will have, at most, one point in common. We re interested in knowing the number of closed polygons, not containing any lines inside, in such diagrams. Figure (a), has only one closed polygon while figure (b) has three. Write a program to do exactly that. Your program will be tested on one or more test cases. Each test case is specified on a separate line. The diagram is specified using a sequence made entirely of (U D L R) and terminated by the letter Q. All letters are capital letters. None of the segments in a test case will overlap. The end of test cases is identified by the letter Q on a line by itself. For each test case, write the answer on a separate line. logo.in UURDLLQ UURRRDLLLLUURRRDDDQ Q 1 3 Page 15 of 16

[J] It s All About Three three.(c cpp java) three.in Blue Consider the series of numbers whose all prime factors have 3 as their least (right-most) digit. For example, the first 10 numbers in this series are: 3 9 13 23 27 39 43 53 69 73 The numbers 3, 13, 23, 43, 53, and 73 are in this series since they re all primes whose least digit isa3. Whereas9(3 3,) 27 (3 3 3,) 39 (3 13,) and 69 (23 3) are in since all their prime factors have a 3 as their least digit. Write a program that takes a list of positive integers and determines if each integer is in this series or not. The input file contains a list of one or more positive integers, each given on a separate line. Each integer is less than a million. The last line of the file contains a -1 (which is not part of the list.) For each number in the input, write, on a separate line, the number itself followed by the word "YES" if the number is in the series described above, or "NO" if it isn t. Separate the number from the answer by a single space. three.in 3 13 33-1 3 YES 13 YES 33 NO Page 16 of 16