Problem A. Jumbled Compass

Similar documents
Problem A. Alignment of Code

Problem D Daydreaming Stockbroker

ACM International Collegiate Programming Contest 2010

Eleventh Annual Ohio Wesleyan University Programming Contest April 1, 2017 Rules: 1. There are six questions to be completed in four hours. 2.

LESSON 2: THE INCLUSION-EXCLUSION PRINCIPLE

Problem F. Chessboard Coloring

March 5, What is the area (in square units) of the region in the first quadrant defined by 18 x + y 20?

Problem A. Worst Locations

FIU Team Qualifier Competition

2015 ACM ICPC Southeast USA Regional Programming Contest. Division 1

ACM Collegiate Programming Contest 2016 (Hong Kong)

2005 Galois Contest Wednesday, April 20, 2005

2. Nine points are distributed around a circle in such a way that when all ( )

CISC 1400 Discrete Structures

Diet customarily implies a deliberate selection of food and/or the sum of food, consumed to control body weight.

n r for the number. (n r)!r!

Sponsored by IBM. 2. All programs will be re-compiled prior to testing with the judges data.

Reading 14 : Counting

2013 ACM ICPC Southeast USA Regional Programming Contest. 2 November, Division 1

Counting Things. Tom Davis March 17, 2006

4th Pui Ching Invitational Mathematics Competition. Final Event (Secondary 1)

2008 ACM ICPC Southeast USA Regional Programming Contest. 25 October, 2008 PROBLEMS

UNIVERSITY OF NORTHERN COLORADO MATHEMATICS CONTEST

PASS Sample Size Software. These options specify the characteristics of the lines, labels, and tick marks along the X and Y axes.

Week 1 Beginner s Course

State Math Contest (Junior)

UW-Madison ACM ICPC Individual Contest

a b c d e f g h 1 a b c d e f g h C A B B A C C X X C C X X C C A B B A C Diagram 1-2 Square names

INTERNATIONAL MATHEMATICS TOURNAMENT OF TOWNS Junior A-Level Paper, Spring 2014.

A complete set of dominoes containing the numbers 0, 1, 2, 3, 4, 5 and 6, part of which is shown, has a total of 28 dominoes.

Live Casino game rules. 1. Live Baccarat. 2. Live Blackjack. 3. Casino Hold'em. 4. Generic Rulette. 5. Three card Poker

Combinatorics: The Fine Art of Counting

LEARN HOW TO PLAY MINI-BRIDGE

IN THIS ISSUE. Cave vs. Pentagroups

BMT 2018 Combinatorics Test Solutions March 18, 2018

Printing: You may print to the printer at any time during the test.

LEVEL I. 3. In how many ways 4 identical white balls and 6 identical black balls be arranged in a row so that no two white balls are together?

Chapter 2. Permutations and Combinations

Investigation. Triangle, Triangle, Triangle. Work with a partner.

Corners! How To Play - a Comprehensive Guide. Written by Peter V. Costescu RPClasses.com

Bridge Players: 4 Type: Trick-Taking Card rank: A K Q J Suit rank: NT (No Trumps) > (Spades) > (Hearts) > (Diamonds) > (Clubs)

Math 1111 Math Exam Study Guide

The Sixth Annual West Windsor-Plainsboro Mathematics Tournament

Problem 2A Consider 101 natural numbers not exceeding 200. Prove that at least one of them is divisible by another one.

Chapter 2 Integers. Math 20 Activity Packet Page 1

TABLE GAMES RULES OF THE GAME

OCTAGON 5 IN 1 GAME SET

PROBLEM SET 2 Due: Friday, September 28. Reading: CLRS Chapter 5 & Appendix C; CLR Sections 6.1, 6.2, 6.3, & 6.6;

Olympiad Combinatorics. Pranav A. Sriram

2016 CCSC Eastern Conference Programming Competition

CSE 312: Foundations of Computing II Quiz Section #1: Counting

Counting. Chapter 6. With Question/Answer Animations

Activity 1: Play comparison games involving fractions, decimals and/or integers.

Problem B Best Relay Team

Solutions to Exercises on Page 86

2009 ACM ICPC Southeast USA Regional Programming Contest. 7 November, 2009 PROBLEMS

TEAM CONTEST. English Version. Time 60 minutes 2009/11/30. Instructions:

The Exciting World of Bridge

International Contest-Game MATH KANGAROO Canada, 2007

CSE 21: Midterm 1 Solution

Part III F F J M. Name

Philadelphia Classic 2013 Hosted by the Dining Philosophers University of Pennsylvania

HIGH SCHOOL - PROBLEMS

PASS Sample Size Software

To play the game player has to place a bet on the ANTE bet (initial bet). Optionally player can also place a BONUS bet.

Irish Collegiate Programming Contest Problem Set

Introduction to Mathematical Reasoning, Saylor 111

5CHAMPIONSHIP. Individual Round Puzzle Examples SUDOKU. th WORLD. from PHILADELPHIA. Lead Sponsor

More Probability: Poker Hands and some issues in Counting

MATHEMATICS ON THE CHESSBOARD

Presents: Basic Card Play in Bridge

UNC Charlotte 2012 Algebra

MATHCOUNTS Yongyi s National Competition Sprint Round Problems Name. State DO NOT BEGIN UNTIL YOU ARE INSTRUCTED TO DO SO.

Dutch Sudoku Advent 1. Thermometers Sudoku (Arvid Baars)

Ante or ante wager means the initial wager required to be made prior to any cards being dealt in order to participate in the round of play.

TEXAS HOLD EM BONUS POKER

Maryland State Lottery and Gaming Control Agency Standard Rules Criss Cross Poker

COCI 2008/2009 Contest #3, 13 th December 2008 TASK PET KEMIJA CROSS MATRICA BST NAJKRACI

Intermediate Math Circles November 1, 2017 Probability I

Counting Things Solutions

Grade 7/8 Math Circles Game Theory October 27/28, 2015

Solutions of problems for grade R5

APMOPS MOCK Test questions, 2 hours. No calculators used.

Find the items on your list...but first find your list! Overview: Definitions: Setup:

Acing Math (One Deck At A Time!): A Collection of Math Games. Table of Contents

2014 ACM ICPC Southeast USA Regional Programming Contest. 15 November, Division 1

TASK NOP CIJEVI ROBOTI RELJEF. standard output

1. Eighty percent of eighty percent of a number is 144. What is the 1. number? 2. How many diagonals does a regular pentagon have? 2.

Math is Cool Masters

Math 365 Wednesday 2/20/19 Section 6.1: Basic counting

CSE 231 Fall 2012 Programming Project 8

Organization Team Team ID# If each of the congruent figures has area 1, what is the area of the square?

CSE 312: Foundations of Computing II Quiz Section #1: Counting (solutions)

Combinatorics: The Fine Art of Counting

CLASS - V. 1. Participant should not write his/her name on the questionnaire.

Today s Topics. Sometimes when counting a set, we count the same item more than once

The Human Calculator: (Whole class activity)

I.M.O. Winter Training Camp 2008: Invariants and Monovariants

The Product Rule can be viewed as counting the number of elements in the Cartesian product of the finite sets

MATH CIRCLE, 10/13/2018

Transcription:

Problem A. Jumbled Compass file: 1 second Jonas is developing the JUxtaPhone and is tasked with animating the compass needle. The API is simple: the compass needle is currently in some direction (between 0 and 359 degrees, with north being 0, east being 90), and is being animated by giving the degrees to spin it. If the needle is pointing north, and you give the compass an input of 90, it will spin clockwise (positive numbers mean clockwise direction) to stop at east, whereas an input of 45 would spin it counterclockwise to stop at north west. The compass gives the current direction the phone is pointing and Jonas task is to animate the needle taking the shortest path from the current needle direction to the correct direction. Many ifs, moduli, and even an arctan later, he is still not convinced his minimumdistance function is correct; he calls you on the phone. The first line of input contains an integer n 1 (0 apple n 1 apple 359), the current direction of the needle. The second line of input contains an integer n 2 (0 apple n 2 apple 359), the correct direction of the needle. the change in direction that would make the needle spin the shortest distance from n 1 to n 2. A positive change indicates spinning the needle clockwise, and a negative change indicates spinning the needle counter-clockwise. If the two input numbers are diametrically opposed, the needle should travel clockwise. I.e., in this case, output 180 rather than 180. 315 45 180 270 45 270 90 90-135 Page 1 of 15

Problem B. Game Rank file: 1 second The gaming company Sandstorm is developing an online two player game. You have been asked to implement the ranking system. All players have a rank determining their playing strength which gets updated after every game played. There are 25 regular ranks, and an extra rank, Legend, above that. The ranks are numbered in decreasing order, 25 being the lowest rank, 1 the second highest rank, and Legend the highest rank. Each rank has a certain number of stars that one needs to gain before advancing to the next rank. If a player wins a game, she gains a star. If before the game the player was on rank 625, andthiswasthe third or more consecutive win, she gains an additional bonus star for that win. When she has all the stars for her rank (see list below) and gains another star, she will instead gain one rank and have one star on the new rank. For instance, if before a winning game the player had all the stars on her current rank, she will after the game have gained one rank and have 1 or 2 stars (depending on whether she got a bonus star) on the new rank. If on the other hand she had all stars except one on a rank, and won a game that also gave her a bonus star, she would gain one rank and have 1 star on the new rank. If a player on rank 120 loses a game, she loses a star. If a player has zero stars on a rank and loses a star, she will lose a rank and have all stars minus one on the rank below. However, one can never drop below rank 20 (losing a game at rank 20 with no stars will have no effect). If a player reaches the Legend rank, she will stay legend no matter how many losses she incurs afterwards. The number of stars on each rank are as follows: Rank 2521: 2 stars Rank 2016: 3 stars Rank 1511: 4 stars Rank 101: 5 stars A player starts at rank 25 with no stars. Given the match history of a player, what is her rank at the end of the sequence of matches? The input consists of a single line describing the sequence of matches. Each character corresponds to one game; W represents a win and L a loss. The length of the line is between 1 and 10, 000 characters (inclusive). a single line containing a rank after having played the given sequence of games; either an integer between 1 and 25 or Legend. Page 2 of 15

ACM International Collegiate Programming Contest 2017 WW 25 WWW 24 WWWW 23 WLWLWLWL 24 WWWWWWWWWLLWW 19 WWWWWWWWWLWWL 18 Page 3 of 15

Problem C. Islands file: 2 seconds You are mapping a faraway planet using a satellite. The planet s surface can be modeled as a grid. The satellite has captured an image of the surface. Each grid square is either land (denoted as L ), water (denoted as W ), or covered by clouds (denoted as C ). Clouds mean that the surface could either be land or water; you cannot tell. An island is a region of land where every grid cell in the island is connected to every other by some path, and every leg of the path only goes up, down, left or right. Given an image, determine the minimum number of islands that is consistent with the given image. The first line of input contains two integers, r and c (1 apple r, c apple 50), which are the number of rows and the number of columns of the image. The next r lines will each contain exactly c characters, consisting only of L (representing Land), W (representing Water), and C (representing Clouds). a single integer, which is the minimum number of islands possible. 4 5 CCCCC CCCCC CCCCC CCCCC 3 2 LW CC WL 0 1 Page 4 of 15

Problem D. Bless You Autocorrect! file: 2 seconds Typing on phones can be tedious. It is easy to make typing mistakes, which is why most phones come with an autocorrect feature. Autocorrect not only fixes common typos, but also suggests how to finish the word while you type it. Jenny has recently been pondering how she can use this feature to her advantage, so that she can send a particular message with the minimum amount of typing. The autocorrect feature on Jenny s phone works like this: the phone has an internal dictionary of words sorted by their frequency in the English language. Whenever a word is being typed, autocorrect suggests the most common word (if any) starting with all the letters typed so far. By pressing tab, the word being typed is completed with the autocorrect suggestion. Autocorrect can only be used after the first character of a word has been typed it is not possible to press tab before having typed anything. If no dictionary word starts with the letters typed so far, pressing tab has no effect. Jenny has recently noticed that it is sometimes possible to use autocorrect to her advantage even when it is not suggesting the correct word, by deleting the end of the autocorrected word. For instance, to type the word autocorrelation, Jenny starts typing aut, which then autocorrects to autocorrect (because it is such a common word these days!) when pressing tab. By deleting the last two characters ( ct ) and then typing the six letters lation, the whole word can be typed using only 3 ( aut ) + 1 (tab) + 2 (backspace twice) + 6 ( lation ) = 12 keystrokes, 3 fewer than typing autocorrelation without using autocorrect. Given the dictionary on the phone and the words Jenny wants to type, output the minimum number of keystrokes required to type each word. The only keys Jenny can use are the letter keys, tab and backspace. The first line of input contains two positive integers n (1 apple n apple 10 5 ), the number of words in the dictionary, and m (1 apple m apple 10 5 ), the number of words to type. Then follow n lines with one word per line, sorted in decreasing order of how common the word is (the first word is the most common). No word appears twice in the dictionary. Then follow m lines, containing the words to type. The dictionary and the words to type only use lower case letters a - z. The total size of the input file is at most 1MB. For each word to type, output a line containing the minimum number of keystrokes required to type the corresponding word. Page 5 of 15

ACM International Collegiate Programming Contest 2017 5 5 austria autocorrect program programming computer autocorrelation programming competition zyx austria 12 4 11 3 2 5 3 yogurt you blessing auto correct bless you autocorrect 5 3 9 Page 6 of 15

Problem E. Paint file: 2 seconds You are painting a picket fence with n slats, numbered from 1 to n. There are k painters willing to paint a specific portion of the fence. However, they don t like each other, and each painter will only paint their given portion of the fence if no other painter overlaps their portion. You want to select a subset of painters that do not conflict with each other, in order to minimize the number of unpainted slats. For example, suppose there are 8 slats, and 3 painters. One painter wants to paint slats 1! 3, onewantstopaint2! 6, andonewantstopaint5! 8. By choosing the first and last painters, you can paint most of the slats, leaving only a single slat (slat 4) unpainted, with no overlap between painters. The first line of input contains two integers n (1 apple n apple 10 18 )andk (1 apple k apple 200, 000), where n is the number of slats and k is the number of painters. Each of the next k lines contains two integers a and b (1 apple a apple b apple n), indicating that this painter wants to paint all of the slats between a and b, inclusive. a single integer, which is the smallest number of slats that go unpainted with an optimal selection of painters 8 3 1 3 2 6 5 8 1 Page 7 of 15

Problem F. Exponial file: 2 seconds Everybody loves big numbers (if you do not, you might want to stop reading at this point). There are many ways of constructing really big numbers known to humankind, for instance: Exponentiation: 42 2016 = 42 42... 42, 2016 times. Factorials: 2016! = 2016 2015... 2 1. In this problem we look at their lesser-known love-child the exponial, which is an operation defined for all positive integers n as 2 1 (n 1)(n 2)... exponial(n) =n For example, exponial(1) = 1 and exponial(5) = 5 4321 =6.206 10 183230 which is already pretty big. Note that exponentiation is right-associative: a bc = a (bc). Since the exponials are really big, they can be a bit unwieldy to work with. Therefore we would like you to write a program which computes exponial(n) mod m (the remainder of exponial(n) when dividing by m). The input consists of two integers n (1 apple n apple 10 9 )andm (1 apple m apple 10 9 ). a single integer, the value of exponial(n) mod m. 2 42 2 5 123456789 16317634 94 265 39 Page 8 of 15

Problem G. Artwork file: 5 seconds A template for an artwork is a white grid of n m squares. The artwork will be created by painting q horizontal and vertical black strokes. A stroke starts from square (x 1,y 1 ), ends at square (x 2,y 2 ) (x 1 = x 2 or y 1 = y 2 ) and changes the color of all squares (x, y) to black where x 1 apple x apple x 2 and y 1 apple y apple y 2. The beauty of an artwork is the number of regions in the grid. Each region consists of one or more white squares that are connected to each other using a path of white squares in the grid, walking horizontally or vertically but not diagonally. The initial beauty of the artwork is 1. Your task is to calculate the beauty after each new stroke. The following figure illustrates how the beauty of the artwork varies in Sample 1. The first line of input contains three integers n, m and q (1 apple n, m apple 1000, 1 apple q apple 10 4 ). Then follow q lines that describe the strokes. Each line consists of four integers x1,y1,x2 and y2 (1 apple x 1 apple x 2 apple n, 1 apple y 1 apple y 2 apple m). Either x 1 = x 2 or y 1 = y 2 (or both). For each of the q strokes, output a line containing the beauty of the artwork after the stroke. 4 6 5 2 2 2 6 1 3 4 3 2 5 3 5 4 6 4 6 1 6 4 6 1 3 3 4 3 Page 9 of 15

Problem H. Card Hand Sorting file: 1 second When dealt cards in the card game Plump it is a good idea to start by sorting the cards in hand by suit and rank. The different suits should be grouped and the ranks should be sorted within each suit. But the order of the suits does not matter and within each suit, the cards may be sorted in either ascending or descending order on rank. It is allowed for some suits to be sorted in ascending order and others in descending order. Sorting is done by moving one card at a time from its current position to a new position in the hand, at the start, end, or in between two adjacent cards. What is the smallest number of moves required to sort a given hand of cards? The first line of input contains an integer n (1 apple n apple 52), the number of cards in the hand. The second line contains n pairwise distinct space-separated cards, each represented by two characters. The first character of a card represents the rank and is either a digit from 2 to 9 or one of the letters T, J, Q, K, anda representing Ten, Jack, Queen, King and Ace, respectively, given here in increasing order. The second character of a card is from the set {s, h, d, c} representing the suits spades, hearts, diamonds, and clubs. the minimum number of card moves required to sort the hand as described above. 4 2h Th 8c Qh 7 9d As 2s Qd 2c Jd 8h 4 2h 3h 9c 8c 1 2 0 Page 10 of 15

Problem I. Illumination file: 5 seconds Consider a square grid with lamps in fixed locations. Each lamp can either illuminate its row or its column, but not both. The illumination of each lamp extends over a limited distance. Any square in the grid should only be illuminated by at most one lamp in its row and by at most one lamp in its column (one of each is acceptable, as is just the row, just the column, or neither). Determine if it is possible for all lamps to be lit while satisfying these constraints. The first line of input contains three positive integers, n, r and k (1 apple n, r, k apple 1, 000,k apple n n), where n is the size of one side of the square grid, r is the maximum reach of a lamp, and k is the number of lamps. The next k lines will each contain two positive integers i and j (1 apple i, j apple n), indicating that there is a lamp in the grid at row i, column j. Each lamp can illuminate squares at most r units away, and can also illuminate its own square, so the maximum number of squares it can illuminate is 2r +1. All lamps will be in distinct locations. a single integer, 1 if it is possible to light all of the lamps and 0 if it is not possible. 3 2 5 1 1 1 3 3 1 3 3 2 2 3 2 6 1 1 1 2 1 3 3 1 3 2 3 3 1 0 Page 11 of 15

Problem J. InTents file: 5 seconds A circus is constructing their tent. The tent is a large piece of canvas held up by a given number of various length tent poles. The tent poles go in specific places on the ground, but which tent pole goes in which place is up to you. You need to choose a placement for the given tent poles that maximizes the total volume under the tent. There will always be one central pole at the origin; the other poles are distributed around the periphery. The tent is always drawn tight between the central pole and two adjacent poles on the periphery, forming a perfect triangle. Only the volume under these triangles formed by two adjacent outer poles and the central origin pole counts towards the total volume. Adjacency is by angle around the origin. Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. The first line of input contains an integer n (3 apple n apple 30), which is the number of poles. The next n 1 lines each contains two integers x and y ( 1, 000 apple x, y apple 1, 000), representing a 2D coordinate, giving the locations where the poles may be placed. The locations may not be in order around the origin. After that, there will be n lines, each containing a single integer h (1 apple h apple 100). These are the heights of the poles. One pole must be placed at the origin, and the rest must be placed at the (x, y) coordinates in the input. The (x, y) locations will surround the origin; that is, the polygon formed by the (x, y) locations, in order (by angle around the origin), will strictly include the origin. No two holes will be at the same angle with the origin (i.e. no triangle of roof fabric will have area 0). a single floating point number, which is the maximum volume achievable under the tent. this number to exactly two decimal places, rounded. 5 100 100-200 -200 300-300 -400 400 30 20 50 60 10 8566666.67 Page 12 of 15

Problem K. Water file: 5 seconds A water company is trying to provide water from its pumping station to a mansion. The company owns n water stations, numbered 1...n, which are connected by a variety of pipes. Water can flow through both directions of a pipe, but the total amount of water that can flow through the pipe is bounded by the capacity of the pipe. The water company is constantly improving the pipes, increasing the capacity of various pipes. The water company is conducting k improvements (each of which is permanent after it is executed). An improvement consists of taking a pipe between two locations and increasing its capacity by a fixed amount, or installing a pipe between two locations which are not directly connected by a pipe. After each improvement, the water company wants to know the maximum amount of water the mansion could receive. n(n 1) The first line of input contains three integers, n (2 apple n apple 100), p (0 apple p apple 2 ), and k (1 apple k apple 10, 000), where n is the number of stations, p is the number of initial pipes, and k is the number of improvements. The first station in the list is always the pumping station, and the second is always the mansion. The next p lines will describe the pipes in the initial setup. The lines will each contain three integers, a, b (1 apple a<bapple n) andc (1 apple c apple 1, 000), which indicates that stations a and b are connected by a pipe with capacity c. No(a, b) pair will appear more than once in this section. The next k lines will describe the improvements. The lines will each contain three integers, a, b (1 apple a<bapple n) andc (1 apple c apple 1, 000), which indicates that the pipe connecting stations a and b has its capacity increased by c (if there is currently no pipe between a and b, then one is created with capacity c). Note that it is possible for an (a, b) pair to be repeated in this section. k +1 integers, each on its own line, describing the maximum amount of water that can reach the mansion. The first number is the amount of water reaching the mansion in the initial configuration. The next k numbers are the amounts of water reaching the mansion after each improvement. Page 13 of 15

ACM International Collegiate Programming Contest 2017 3 2 1 1 3 10 2 3 1 2 3 15 1 10 6 10 2 1 3 2 1 4 6 1 5 1 3 5 8 4 5 7 2 4 3 2 5 4 2 6 1 5 6 9 3 6 5 2 6 9 1 6 3 8 9 12 Page 14 of 15

Problem L. Barbells file: 1 second Your local gym has b bars and p plates for barbells. In order to prepare a weight for lifting, you must choose a single bar, which has two sides. You then load each side with a (possibly empty) set of plates. For safety reasons, the plates on each side must balance; they must sum to the same weight. The combination of plates on either side might be different, but the total weight on either side must be the same. What weights are available for lifting? The first line of input contains two integers, b and p (1 apple b, p apple 14), representing the number of bars and plates. Then, there are b lines each containing a single integer x (1 apple x apple 10 8 ) which are the weights of the bars. After that, there are p lines each containing a single integer y (1 apple y apple 10 8 ) which are the weights of the plates. a sorted list of all possible lifting weights, one per line. There must be no duplicates. 2 5 100 110 5 5 1 4 6 100 110 112 120 122 130 Page 15 of 15