BAPC The Problem Set

Similar documents
Analyzing Games: Solutions

CS61B, Fall 2014 Project #2: Jumping Cubes(version 3) P. N. Hilfinger

2 Textual Input Language. 1.1 Notation. Project #2 2

OCTAGON 5 IN 1 GAME SET

Underleague Game Rules

Welcome to Family Dominoes!

Project 1: A Game of Greed

STUDENT S BOOKLET. Geometry 2. Contents. Meeting 7 Student s Booklet. May 24 UCI. 1 Circular Mountains 2 Rotations

UW-Madison ACM ICPC Individual Contest

Problems translated from Croatian by: Paula Gombar

Problem 4.R1: Best Range

Optimal Yahtzee performance in multi-player games

Bouncy Dice Explosion

Programming an Othello AI Michael An (man4), Evan Liang (liange)

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

Cross Out Singles. 3. Players then find the sums of the rows, columns, and diagonal, and record them in the respective circles.

Alberta 55 plus Cribbage Rules

UTD Programming Contest for High School Students April 1st, 2017

The game consists of 3 rounds where you will build a castle in 30 seconds then place catapults and steal wall pieces from your neighbors.

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

Adjustable Group Behavior of Agents in Action-based Games

CS 371M. Homework 2: Risk. All submissions should be done via git. Refer to the git setup, and submission documents for the correct procedure.

G51PGP: Software Paradigms. Object Oriented Coursework 4

ProCo 2017 Advanced Division Round 1

Problem A The Amazing Human Cannonball

2015 ACM ICPC Southeast USA Regional Programming Contest. Division 1

CS1802 Week 9: Probability, Expectation, Entropy

RMT 2015 Power Round Solutions February 14, 2015

The game of Paco Ŝako

A fun way to challenge your math thinking! Grade Levels: 4th - 8th Time: 1 class period. Check out 36 BINGO Snapshot

Problem A To and Fro (Problem appeared in the 2004/2005 Regional Competition in North America East Central.)

Cycle Roulette The World s Best Roulette System By Mike Goodman

Maths games and activities to help your child s learning Enjoy!

Spring 06 Assignment 2: Constraint Satisfaction Problems

CPSC 217 Assignment 3 Due Date: Friday March 30, 2018 at 11:59pm

Building Successful Problem Solvers

Lesson 1: The Rules of Pentago

Problem A. First Mission

CS103 Handout 25 Spring 2017 May 5, 2017 Problem Set 5

B1 Problem Statement Unit Pricing

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

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

Bouncy Dice Explosion

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

Problem F. Chessboard Coloring

THE STORY GAME PLAY OVERVIEW

Ch. 670a SIX-CARD FORTUNE PAI GOW POKER a.1. CHAPTER 670a. SIX-CARD FORTUNE PAI GOW POKER

Probability: Part 1 1/28/16

Go through the whole list above and make all of them at least acceptably polite, without looking below and then using the words below to help you.

Documentation and Discussion

South African Computer Olympiad Final Round Day 2. Overview. Carruthers- Smith Problem parrots seen search. seen.java seen.py seen.c seen.cpp seen.

By Scott Fallstrom and Brent Pickett The How and Whys Guys

1. For which of the following sets does the mean equal the median?

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

Wordy Problems for MathyTeachers

Figure 1: The Game of Fifteen

GCPC

MAGISTRATVM A Group Projects game for the piecepack

CS 787: Advanced Algorithms Homework 1

Westminster College 2012 High School Programming Contest. October 8, 2012

Assignment 6 Play A Game: Minesweeper or Battleship!!! Due: Sunday, December 3rd, :59pm

Name: Exam Score: /100. Exam 1: Version C. Academic Honesty Pledge

SGU 149. Computer Network. time limit per test: 0.50 sec. memory limit per test: 4096 KB input: standard input output: standard output

A Mathematical Analysis of Oregon Lottery Keno

Maths Is Fun! Activity Pack Year 1

Preliminaries. for the Benelux Algorithm Programming Contest. Problems

Overview. Equipment. Setup. A Single Turn. Drawing a Domino

Q i e v e 1 N,Q 5000

Would You Like To Earn $1000 s With The Click Of A Button?

COMPONENTS. by harry-pekka Kuusela. 1 central board. 4 player boards 2-4 (-8) (-90) 12+

Would You Like To Earn $1000 s With The Click Of A Button?

ASSEMBLY OBJECT OF THE GAME. The Game of Mystery, Suspicion and Foul Play!

CMSC 201 Fall 2018 Project 3 Sudoku

Milton Public Schools Elementary Summer Math

CHAPTER 659a. FORTUNE ASIA POKER

Math 147 Lecture Notes: Lecture 21

Tetris: A Heuristic Study

Equipment for the basic dice game

Tutorial: Creating maze games

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

Irish Collegiate Programming Contest Problem Set

Presentation by Toy Designers: Max Ashley

Problem A. Backward numbers. backw.in backw.out

Figure 1: A Checker-Stacks Position

The 2016 ACM-ICPC Asia China-Final Contest Problems

Determine the Expected value for each die: Red, Blue and Green. Based on your calculations from Question 1, do you think the game is fair?

COMP3211 Project. Artificial Intelligence for Tron game. Group 7. Chiu Ka Wa ( ) Chun Wai Wong ( ) Ku Chun Kit ( )

Gough, John , Doing it with dominoes, Australian primary mathematics classroom, vol. 7, no. 3, pp

Is muddled about the correspondence between multiplication and division facts, recording, for example: 3 5 = 15, so 5 15 = 3

Use the following games to help students practice the following [and many other] grade-level appropriate math skills.

Spring 06 Assignment 2: Constraint Satisfaction Problems

Okay, that s enough talking. Let s get things started. Here s the photo I m going to be using in this tutorial: The original photo.

The game of Reversi was invented around 1880 by two. Englishmen, Lewis Waterman and John W. Mollett. It later became

Making Middle School Math Come Alive with Games and Activities

Card Racer. By Brad Bachelor and Mike Nicholson

A1 Problem Statement Unit Pricing

Exceptional & Free Online Resources for Teaching Probability

Targets for pupils in Year 4

Targets for pupils in Year 4

LEARNING ABOUT MATH FOR K TO 5. Dorset Public School. April 6, :30 pm 8:00 pm. presented by Kathy Kubota-Zarivnij

Transcription:

BAPC 2012 The 2012 Benelux Algorithm Programming Contest The Problem Set A B C D E F G H I J Another Dice Game Black Out Chess Competition Digit Sum Encoded Message Fire Good Coalition Hot Dogs in Manhattan Integer Lists John s Book Stack

These problem texts are copyright by the BAPC 2012 jury. They are licensed under the Creative Commons Attribution-Share Alike license version 3.0; The complete license text can be found at: http://creativecommons.org/licenses/by-sa/3.0/legalcode

Problem A: Another Dice Game 1 A Another Dice Game In the game Pickomino 1 one has to throw 8 dice to reach at least a certain target score. The rules are as follows: The dice contain the values 1, 2, 3, 4, 5 and worm. The dice are fair, so all outcomes are equally likely. The game is started by throwing all dice. After a throw, the player must pick one of the six possible values and put all dice with this value aside. There must be at least one die with this value. After putting some dice aside, the player may choose to either throw the remaining dice again or stop. The player may only stop after at least one worm has been put aside. Each possible value may only be chosen once during the game. When the player stops, his total score is the sum of the values of the dice that were put aside. A worm is worth 5 points. The player can get stuck by throwing only values that were already put aside, by having put all dice aside but not having a worm or by not having reached the target score. If the player is stuck he scores 0 points and the game is ended. Jan is playing Pickomino and wants to score at least n points. When Jan uses an optimal strategy, what is the probability that he reaches this target? On the first line one positive number: the number of test cases, at most 100. After that per test case: one line with the integer n (1 n 40): the target value. Per test case: one line with a floating point number: the probability that you score at least n points when using an optimal strategy. This number should be accurate up to 10 6 relative or absolute precision. 1 Dutch people may know this game as Regenwormen

2 Problem A: Another Dice Game Sample in- and output 3 5 21 40 0.9934260978934218 0.8930267371507457 0.0001461079070016448 To reach 5 points it is enough to throw at least one worm. The optimal strategy in this case is therefore to stop as soon as you have a worm. If you did not throw a worm, you should put aside as few dice as possible to maximize the chance of throwing a worm in a later throw.

Problem B: Black Out 3 B Black Out When you ve finished solving all problems in this contest, there s no need to get bored, because we introduce a new and fun game called Black Out! Grab a piece of paper and draw a table of 5 by 6 squares. Next, choose your favorite teammate to play against. Each player in turn selects one or more squares that are adjacent and in the same row or column, and colors them all black. Some of these squares may be black already, but at least one of them must not be. The winner is the player to color the last square(s) black. Once you got the hang of it, you might want to try and write your own AI player. You can then submit it and let it play a few games against our (= the jury s) player! After a lengthy analysis, we have managed to prove that the game is theoretically won by the player who starts, so we ll gracefully let your player have the first move every time. If you manage to beat our player in every game, you ll be awarded another point in this contest. But be careful: the jury s player is not to be underestimated and will surely grab any chance it is offered! If you lose, you ll get a Wrong Answer. Also note that we are not that patient, so make sure your player is quick to move. 1 2 3 4 5 The move 2 6 5 6 as given in the sample makes all squares from (2,6) to (5,6) black. The squares (3,6) and (4,6) were black already. and output This is a problem with dynamic input and output, read the following description very carefully. The first line of the input contains one positive number: the number of games, at most 100. Then, for each game: Your program writes a move on a single line to standard output. A move consists of four space-separated integers r 1, c 1, r 2 and c 2 (1 r 1 r 2 5 and 1 c 1 c 2 6; also, r 1 = r 2 and/or c 1 = c 2 ) on a single line: the row and column number of the two squares between which all squares are colored black (including the two indicated squares). In case only one square is colored black, r 1 = r 2 and c 1 = c 2. After each move, our program writes one of the following two responses on a single line to standard input:

4 Problem B: Black Out Result The word MOVE, followed by a single space, followed by four space-separated integers, representing the response of our program. Your program must now make another move. The word GAME, indicating that the game has ended: either your program has won, or our program intends to make a move that ends the game in its favor. These are the possible causes for some of the possible results of your submission: CORRECT Your program has won all games. Congratulations! RUN-ERROR There was an error during the execution of your program, or your program s output did not adhere to the specified format and constraints, or all the squares that you wanted colored black were black already (invalid move). TIMELIMIT Your program was too slow or it did not respond. WRONG-ANSWER Your program has successfully completed all games, but it has not won all of them. Notes Make sure to print a newline after your move. C users: Do setlinebuf(stdout); at the start of your program to make sure output is flushed correctly. If you use scanf to read the moves (which we recommend), then do not read the newline character at the end. So, to read the input with scanf, use scanf("%s",s) and scanf("%d %d %d %d", &r1, &c1, &r2, &c2);. Also, do not use scanf("move") or scanf("game"). C++ users: Recommendation: use std::cin and std::cout to read input and write output. This will ensure output is flushed correctly. Java/C# users: Do not use buffered output; either System.out.println or System.Console.WriteLine will do fine. Haskell users: Do hsetbuffering stdout LineBuffering at the beginning of main.

Problem B: Black Out 5 Sample in- and output Notes: This example is merely to illustrate the communication between your program and the jury s program; it does not demonstrate an example of optimal play for either player. The extra newlines in the example below are for clarity only, to demonstrate the order of events; you should print exactly one newline character after each move, and the input contains no blank lines either. 1 MOVE 3 6 3 6 MOVE 4 2 4 6 MOVE 2 6 5 6 MOVE 3 1 5 1 MOVE 5 2 5 5 GAME 2 1 2 4 1 3 5 3 4 1 4 6 1 1 1 6 3 2 3 5 2 5 2 5

Almost blank page

Problem C: Chess Competition 7 C Chess Competition In a chess competition, every player plays one game against every other player. The winner receives one point, the loser none. In case of a draw, both players receive half a point. When all games have been played, whoever scored the most points wins the competition. If multiple competitors are tied for the highest score, they will play a series of tie-break games to determine the winner. For this problem we consider a competition where the games are played in arbitrary order. Based on the outcome of the games that have been played so far (which could be all, or none, or anything in between) the organizers want to determine which players can still win the competition. On the first line one positive number: the number of test cases, at most 100. After that per test case: one line with an integer n (2 n 30): the number of players. n lines with n characters each, describing the intermediate results. The j-th character on the i-th line gives the result of the i-th player against the j-th player: 1 for a win, 0 for a loss, d for a draw,. if this game has not been played yet, x when i = j (since competitors do not play against themselves). The intermediate results are guaranteed to be internally consistent. More formally, if the j-th character on the i-th line is a digit ( 0 or 1 ) then the i-th character on the j-th line will be the other digit. In all other cases, the j-th character on the i-th line equals the i-th character on the j-th line. Per test case: one line with the 1-based indices of all the players that can possibly win the competition, in increasing order, separated by spaces.

8 Problem C: Chess Competition Sample in- and output 3 5 x.11d.x1d1 00x.0 0d.x. d01.x 7 x00111. 1x01d.d 11x1.00 000x000 0d.1xd1 0.11dxd.d110dx 7 x00011. 1x00d.d 11x0.0. 111x111 0d.0xd. 0.10dx..d.0..x 1 2 1 2 3 5 6 7 4

Problem D: Digit Sum 9 D Digit Sum For a pair of integers a and b, the digit sum of the interval [a, b] is defined as the sum of all digits occurring in all numbers between (and including) a and b. For example, the digit sum of [28, 31] can be calculated as: 2+8 + 2+9 + 3+0 + 3+1 = 28 Given the numbers a and b, calculate the digit sum of [a, b]. On the first line one positive number: the number of test cases, at most 100. After that per test case: one line with two space-separated integers, a and b (0 a b 10 15 ). Per test case: one line with an integer: the digit sum of [a, b]. Sample in- and output 3 0 10 28 31 1234 56789 46 28 1128600

Almost blank page

Problem E: Encoded Message 11 E Encoded Message Alex wants to send a love poem to his girlfriend Bridget. Unfortunately, she has a nosy friend, Ellen, who might intercept his message and invade their privacy. To prevent this, Alex has invented a scheme to make his missives indecipherable to Ellen. He arranges the letters into a square, which is rotated a quarter-turn clockwise, and then he puts the resulting letters on a single line again. (For simplicity s sake, Alex doesn t use whitespace or punctuation in his poems.) For example, the text RosesAreRedVioletsAreBlue would be encoded as eedarbtvrolsiesuaoreerles using the following intermediate steps: R o s e s A r e R e d V i o l e t s A r e B l u e e e d A R B t V r o l s i e s u A o R e e r l e s Ellen has intercepted some of Alex s messages but they make no sense to her. Can you write a program to help her decode them? On the first line one positive number: the number of test cases, at most 100. After that per test case: one line with an encoded message: a string consisting of upper-case and lower-case letters only. The length of the message is a square between 1 and 10 000 characters. Per test case: one line with the original message. Sample in- and output 3 RSTEEOTCP eedarbtvrolsiesuaoreerles EarSvyeqeBsuneMa TOPSECRET RosesAreRedVioletsAreBlue SquaresMayBeEven

Almost blank page

Problem F: Fire 13 F Fire You are trapped in a building consisting of open spaces and walls. Some places are on fire and you have to run for the exit. Will you make it? At each second, the fire will spread to all open spaces directly connected to the North, South, East or West side of it. Fortunately, walls will never catch fire and will keep the fire inside the building, so as soon as you are out of the building you will be safe. To run to any of the four open spaces adjacent to you takes you exactly one second. You cannot run through a wall or into an open space that is on fire or is just catching fire, but you can run out of an open space at the same moment it catches fire. Given a map of the building, decide how fast you can exit the building. On the first line one positive number: the number of test cases, at most 100. After that per test case: one line with two space-separated integers w and h (1 w, h 1 000): the width and height of the map of the building, respectively. h lines with w characters each: the map of the building, consisting of. : a room, # : a wall, @ : your starting location, * : fire. There will be exactly one @ in the map. Per test case: one line with a single integer which is the minimal number of seconds that you need to exit the building or the string IMPOSSIBLE when this is not possible.

14 Problem F: Fire Sample in- and output 5 4 3 #### #*@. #### 7 6 ###.### #*#.#*# #...# #...# #..@..# ####### 7 4 ###.### #...*# #@...#.###### 5 5....***..*@*..***.... 3 3 ### #@# ### 2 5 IMPOSSIBLE IMPOSSIBLE IMPOSSIBLE

Problem G: Good Coalition 15 G Good Coalition The Dutch political system is in turmoil. There have been six coalition governments in the past fourteen years, all of which have fallen before completing their term in office. Recently there have been elections (again), the outcome of which has been described as impossible by several political commentators. The only bright spot in this bleak situation is that they have appointed you as the informateur. As the informateur it is your task to find a suitable coalition. Being the rational person you are, you have decided the first negotiation attempt should be started between the parties forming the most stable coalition. A coalition is formed by a set of parties having won a strict majority of seats in the election (i.e. at least 76 seats out of a total of 150). The most stable coalition is one that has the highest chance of completing its term in office. A coalition falls (and new elections must be held) if a single party leaves the coalition. The probability of a coalition completing their term is estimated by the product of the probabilities of each party in the coalition completing their term. This probability is in turn based on historical data. Find the best coalition and save the Netherlands from becoming a banana republic! On the first line one positive number: the number of test cases, at most 100. After that per test case: one line with an integer n (1 n 150), the number of political parties that have won at least one seat in the election. n lines, each with two space-separated integers s i and p i (1 s i 150 and 1 p i 100): the number of seats won by the i-th party and the probability (expressed as a percentage) that the i-th party will complete its term in office, respectively. ( n ) Note that there are exactly 150 seats divided among all parties s i = 150. i=1 Per test case: one line with a floating point number: the probability (expressed as a percentage) of the most stable coalition sitting out their term in office. This number should be accurate up to 10 6 relative or absolute precision. Sample in- and output 1 4 35 80 25 70 60 60 30 90 54.0

Almost blank page

Problem H: Hot Dogs in Manhattan 17 H Hot Dogs in Manhattan The two friends Barack and Mitt have both decided to set up their own hot dog stand in Manhattan. They wish to find the two optimal locations for their stands. First of all, they both want to put their stand at an intersection, since that gives them maximum exposure. Also, this being Manhattan, there are already quite a few stands in the city, also at intersections. If they put up a stand close to another (or each other s) stand, they might not get that many customers. They would therefore like to put their stands as far from other stands as possible. We model Manhattan as a finite square grid, consisting of w vertical streets and h horizontal streets. The vertical streets run from x = 0 to x = w 1, while horizontal streets run from y = 0 to y = h 1. All pairs of consecutive parallel streets are separated by the same distance, which we set as the unit distance. The distance between two intersections (x 1, y 1 ) and (x 2, y 2 ) is then given by x 1 x 2 + y 1 y 2. We indicate an intersection s suitability by its privacy, which is the minimum of all distances from this intersection to all other hot dog stands. Barack and Mitt would like to find two intersections with the maximum amount of privacy, i.e. such that the smallest of the two privacies is as large as possible. Note that the privacy of Barack s location can be determined by the distance to Mitt s location and vice versa. On the first line one positive number: the number of test cases, at most 100. After that per test case: one line with three space-separated integers n, w and h (0 n 1 000 and 2 w, h 1 000): the number of hot dog stands already in place and the number of vertical and horizontal streets, respectively. n lines, each with two space-separated integers x i and y i (0 x i < w and 0 y i < h): the intersection where the i-th hot dog stand is located. All hot dog stands are at different intersections. At least two intersections do not contain a stand. Per test case: one line with one integer: the maximum privacy that Barack and Mitt can both obtain.

18 Problem H: Hot Dogs in Manhattan Sample in- and output 3 1 4 4 0 1 6 6 6 0 0 1 1 2 2 3 3 4 4 5 5 2 8 3 0 0 7 0 These sample cases are illustrated below. Only for the first case, the optimal placement of the two new stands is given (indicated by the dashed outlines). 4 5 3 y x 0 x 0 1 2 3 y 0 1 2 3 4 5 0 1 1 2 2 3 3 4 5 y x 0 0 1 2 3 4 5 6 7 1 2

Problem I: Integer Lists 19 I Integer Lists The programming language Better And Portable Code (BAPC) is a language for working with lists of integers. The language has two built-in functions: R (reverse) and D (drop). The function R reverses its input list, and D drops the first element of its input and returns the rest, or gives an error in case its input is an empty list. To get more advanced behavior, functions can be composed: AB is the function that first applies A to its input and then B to the resulting list. For example, RDD is a function that reverses a list and then drops the first two elements. Unfortunately, our BAPC interpreter has bit rotted, so we ask you to write a new one. Given a BAPC program and its input, return its output or error in case D is applied to an empty list. Lists are represented as the character [ followed by a comma-separated list of integers followed by the character ]. Notice that the input and output lists can be quite long. On the first line one positive number: the number of test cases, at most 100. After that per test case: one line with a string p (1 length(p) 100 000): a BAPC program, consisting of the characters R and D. one line with an integer n (0 n 100 000): the number of elements in the input. one line with a list of n integers in the form [x 1,..., x n ] (1 x i 100): the input list. Per test case: one line with the resulting integer list or error in case of an error. Sample in- and output 4 RDD 4 [1,2,3,4] DD 1 [42] RRD 6 [1,1,2,3,5,8] D 0 [] [2,1] error [1,2,3,5,8] error

Almost blank page

Problem J: John s Book Stack 21 J John s Book Stack John has a big stack of books of various sizes. Such a stack is stable if the books have nondecreasing sizes (viewed from top to bottom); otherwise, it is unstable, and likely to fall over. To prevent this, John wants to sort the books in the stack by size. He does so by pulling out a book from somewhere in the middle (or bottom) of the stack and then putting it back on top. However, he can only pull out a book safely if the books on top of it already form a stable stack. For example, if John has a stack of four books with sizes 3, 4, 1 and 2 (from top to bottom) then he can sort them as follows: Your task is to determine how many steps are required to sort a given stack of books. In the example above, which corresponds to the first sample case, the answer is 3. On the first line one positive number: the number of test cases, at most 100. After that per test case: one line with an integer n (1 n 50): the number of books. one line containing n space-separated integers s i (1 s i 1 000 for 1 i n): the sizes of the books, as they appear in the initial stack from top to bottom. Per test case: one line with an integer: the minimum number of steps required to sort the stack using the algorithm described above. Sample in- and output 4 4 3 4 1 2 8 3 1 4 1 5 9 2 6 5 1 42 42 42 1000 22 4 1 2 5 6 7 9 10 3 13 17 11 12 14 19 20 22 8 15 16 18 21 3 53 0 1234567

Almost blank page