Problem Set 7: Games Spring 2018

Similar documents
Problem F. Chessboard Coloring

BMT 2018 Combinatorics Test Solutions March 18, 2018

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

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

Problem A: Ordering supermarket queues

Southeastern European Regional Programming Contest Bucharest, Romania Vinnytsya, Ukraine October 21, Problem A Concerts

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

Take one! Rules: Two players take turns taking away 1 chip at a time from a pile of chips. The player who takes the last chip wins.

ACM ICPC World Finals Warmup 2 At UVa Online Judge. 7 th May 2011 You get 14 Pages 10 Problems & 300 Minutes

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

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

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

FRI Summer School Final Contest. A. Flipping Game

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

ProCo 2017 Advanced Division Round 1

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

2005 Galois Contest Wednesday, April 20, 2005

Grade 6 Math Circles Combinatorial Games November 3/4, 2015

PLAYERS AGES MINS.

Sponsored by IBM. 6. The input to all problems will consist of multiple test cases unless otherwise noted.

Grade 6 Math Circles Combinatorial Games - Solutions November 3/4, 2015

PRIMES STEP Plays Games

UNC Charlotte 2012 Comprehensive

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

Q i e v e 1 N,Q 5000

Counters in a Cup In and Out. The student sets up the cup, drops the counters on it, and records how many landed in and out of the cup.

Solutions to Exercises on Page 86

CSE548, AMS542: Analysis of Algorithms, Fall 2016 Date: Sep 25. Homework #1. ( Due: Oct 10 ) Figure 1: The laser game.

Problem A. First Mission

Solutions of problems for grade R5

18.S34 (FALL, 2007) PROBLEMS ON PROBABILITY

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

Games of Skill ANSWERS Lesson 1 of 9, work in pairs

SECTION ONE - (3 points problems)

TASK NOP CIJEVI ROBOTI RELJEF. standard output

Figure 1: The Game of Fifteen

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

Analyzing Games: Solutions

Probability. Misha Lavrov. ARML Practice 5/5/2013

2016 Canadian Computing Olympiad Day 2, Problem 1 O Canada

The 2016 ACM-ICPC Asia China-Final Contest Problems

Canadian Mathematics Competition An activity of The Centre for Education in Mathematics and Computing, University of Waterloo, Waterloo, Ontario

Problem Set 7: Network Flows Fall 2018

Problem A: Complex intersecting line segments

Jim and Nim. Japheth Wood New York Math Circle. August 6, 2011

What You Need to Know Page 1 HANG 10! Write addition and subtraction expressions that equal 10.

Team Round University of South Carolina Math Contest, 2018

SMT 2014 Advanced Topics Test Solutions February 15, 2014

UW-Madison ACM ICPC Individual Contest

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

12. 6 jokes are minimal.

Senior Math Circles February 10, 2010 Game Theory II

COMPSCI 223: Computational Microeconomics - Practice Final

ACM International Collegiate Programming Contest 2010

IN THIS ISSUE. Cave vs. Pentagroups

2015 ACM ICPC Southeast USA Regional Programming Contest. Division 1

Spring 06 Assignment 2: Constraint Satisfaction Problems

Problem A Rearranging a Sequence

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

For all questions, answer choice E) NOTA means that none of the above answers is correct.

Positive Triangle Game

Plan. Related courses. A Take-Away Game. Mathematical Games , (21-801) - Mathematical Games Look for it in Spring 11

LESSON 2: THE INCLUSION-EXCLUSION PRINCIPLE

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?

A Games-based, Strategy-focused Fluency Plan

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

Problem A. Jumbled Compass

BRITISH COLUMBIA SECONDARY SCHOOL MATHEMATICS CONTEST, 2006 Senior Preliminary Round Problems & Solutions

Grade 7 & 8 Math Circles. Mathematical Games

Sept. 26, 2012

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

Week 1. 1 What Is Combinatorics?

Preliminaries. for the Benelux Algorithm Programming Contest. Problems

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

Cayley Contest (Grade 10) Thursday, February 25, 2010

Contest 1. October 20, 2009

7. Three friends each order a large

SUMMER MATHS QUIZ SOLUTIONS PART 2

Problem A. Worst Locations

November 8, Chapter 8: Probability: The Mathematics of Chance

UNC Charlotte 2012 Algebra

GEOGRAPHY PLAYED ON AN N-CYCLE TIMES A 4-CYCLE

Grab Bag Math ➊ ➋ ➌ ➍ ➎ ➏ ON THEIR OWN. Can you figure out all the ways to build one-layer rectangular boxes with Snap Cubes?

(1) 2 x 6. (2) 5 x 8. (3) 9 x 12. (4) 11 x 14. (5) 13 x 18. Soln: Initial quantity of rice is x. After 1st customer, rice available In the Same way

On Variations of Nim and Chomp

CS1800: More Counting. Professor Kevin Gold

Olympiad Combinatorics. Pranav A. Sriram

HOW TO PLAY Shape Card Games

Fall 2018 #11 Games and Nimbers. A. Game. 0.5 seconds, 64 megabytes

Mathematical Olympiads November 19, 2014

English Version. Instructions: Team Contest

Table of Contents. Table of Contents 1

Comprehensive Rules Document v1.1

BAPC The Problem Set

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

The Canadian Open Mathematics Challenge November 3/4, 2016

BmMT 2015 Puzzle Round November 7, 2015

2008 Canadian Computing Competition: Senior Division. Sponsor:

UCF Local Contest August 31, 2013

Wordy Problems for MathyTeachers

Transcription:

Problem Set 7: Games 15-95 Spring 018 A. Win or Freeze time limit per test: seconds : standard : standard You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself. The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move. 13 The first line contains the only integer q (1 q 10 ). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. In the first line print the number of the winning player (1 or ). If the first player wins then the second line should contain another integer his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them. 6 30 1 6 1 1 0 Note Number 6 has only two non-trivial divisors: and 3. It is impossible to make a move after the numbers and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory.

B. Dinner with Emma time limit per test: 1 second : standard : standard Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is c ij. Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love. The first line contains two integers n, m (1 n, m 100) the number of streets and avenues in Munhattan. Each of the next n lines contains m integers c (1 c 10 ) the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue. Print the only integer a the cost of the dinner for Jack and Emma. ij ij 9 3 4 4 1 3 5 5 4 5 1 3 3 1 3 3 1 3 1 1 Note In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.

C. Game time limit per test: seconds : standard : standard Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid line (not necessarily from border to border). The part of the paper, that touches the knife at least once, is considered cut. There is one limit not to turn the game into an infinite cycle: each move has to cut the paper, that is the knife has to touch the part of the paper that is not cut before. Obviously, the game ends when the entire sheet is cut into 1 1 blocks. During the game, the pieces of the sheet are not allowed to move. It is also prohibited to cut along the border. The coordinates of the ends of each cut must be integers. You are given an n m piece of paper, somebody has already made k cuts there. Your task is to determine who will win if the players start to play on this sheet. You can consider that both players play optimally well. If the first player wins, you also need to find the winning first move. 9 5 The first line contains three integers n, m, k (1 n, m 10, 0 k 10 ) the sizes of the piece of paper and the number of cuts. Then follow k lines, each containing 4 integers xb, yb, xe, ye (0 xb, xe n, 0 yb, ye m) the coordinates of the ends of the existing cuts. i i i i i i i i It is guaranteed that each cut has a non-zero length, is either vertical or horizontal and doesn't go along the sheet border. The cuts may intersect, overlap and even be the same. That is, it is not guaranteed that the cuts were obtained during any correct game. If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow format to print them). 1 0 FIRST 1 0 1 1 4 0 1 1 0 1 1 1 1 0 1 1 1 SECOND

D. Yet Another Number Game time limit per test: seconds : standard : standard Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games! Since you are so curious about Bitland, I'll give you the chance of peeking at one of these games. BitLGM and BitAryo are playing yet another of their crazy-looking genius-needed Bitlandish games. They've got a sequence of n non-negative integers a, a,..., a. The players make moves in turns. BitLGM moves first. Each player 1 n can and must do one of the two following actions in his turn: Take one of the integers (we'll denote it as a ). Choose integer x (1 x a ). And then decrease a by x, that is, apply assignment: a = a - x. i Choose integer x. And then decrease all a by x, that is, apply assignment: a = a - x, for all i. The player who cannot make a move loses. i You're given the initial sequence a, a,..., a. Determine who wins, if both players plays optimally well and if BitLGM and 1 n BitAryo start playing the described game in this sequence. The first line contains an integer n (1 n 3). The next line contains n integers a, a,..., a (0 a < 300). 1 n i i i i i i i Write the name of the winner (provided that both players play optimally well). Either "BitLGM" or "BitAryo" (without the quotes). 1 1 BitLGM 1 BitAryo 3 1 1 BitLGM

E. Game of Cards Alice and Bob created a new game while at the beach this summer. All they need is a set of numbered playing cards. They start by creating P piles with all cards faceup and select a non-negative number K. After that,they take turns like this: 1. Aplayerstartsbyselectingoneofthepiles.. Then, he removes from 0 up to K cards from the top of that pile, leaving at least one card in the pile. 3. Next, he looks at the card left at the top of the pile and must remove a number of cards equal to its value (from the top of the same pile). Whoever doesn t have more cards to remove, or whoever is forced to remove more cards than those available on a pile, loses the game. In the figure, you can see an example with two piles and K =1. The player to move might: a) Select the first pile and 0 cards to remove, being forced to remove 1 card from the top next. b) Select the second pile and 0 cards to remove, having to remove 1 card from the top next. c) Select the second pile and 1 card to remove, having to remove cards from the top next. Alice has realized that Bob is very good at this game and will always win if he has the chance. Luckily, this time Alice is first to play. Is Alice able to win this game? Task Given the description of the piles with all the cards and the maximum number of cards they can start to remove, your goal is to find out whether Alice can win the game if she is the first to play.

The first line contains space separated integers, P,thenumberofpiles,andK, the maximum number of cards they can start to remove on their turn. The next P lines start with an integer N, indicatingthenumberofcardsonapile. N space separated integers follow, representing the cards on that pile from the bottom to the top. Constraints 1 apple P apple 100 Number of piles. 1 apple K apple 10 Maximum number of cards a player can start to remove. 1 apple c apple 10 Number on each card. 1 apple N apple 1000 Size of each pile. A single string, stating Alice can win. or Bob will win., as appropriate. Sample 1 4 1 4 1 1 1 1 6 1 1 1 4 1 1 1 1 6 1 1 1 Sample 1 Bob will win. 1 Explanation The piles are the same, so Bob will always be able to mirror whatever move Alice makes. Sample 1 1 1 3 1 1 Sample Alice can win. Explanation Alice can start by removing 0 cards from the second pile and then 1 card from its top. Two legal moves will be possible next, Bob will make one and Alice the other. Sample 3 5 3 1 1 5 5 4 3 1 Sample 3 Alice can win.

F. Playing with String time limit per test: seconds : standard : standard Two people play the following string game. Initially the players have got some string s. The players move in turns, the player who cannot make a move loses. Before the game began, the string is written on a piece of paper, one letter per cell. An example of the initial situation at s = "abacaba" A player's move is the sequence of actions: 1. The player chooses one of the available pieces of paper with some string written on it. Let's denote it is t. Note that initially, only one piece of paper is available.. The player chooses in the string t = t1t... t t character in position i (1 i t ) such that for some positive integer l (0 < i - l; i + l t ) the following equations hold: t = t, t = t,..., t = t. i - 1 i + 1 i - i + i - l i + l 3. Player cuts the cell with the chosen character. As a result of the operation, he gets three new pieces of paper, the first one will contain string t t... t contains string t t... t. i + 1 i + 1 i - 1, the second one will contain a string consisting of a single character t i, the third one t An example of making action (i = 4) with string s = «abacaba» Your task is to determine the winner provided that both players play optimally well. If the first player wins, find the position of character that is optimal to cut in his first move. If there are multiple positions, print the minimal possible one. The first line contains string s (1 s 5000). It is guaranteed that string s only contains lowercase English letters. If the second player wins, print in the single line "Second" (without the quotes). Otherwise, print in the first line "First" (without the quotes), and in the second line print the minimal possible winning move integer i (1 i s ). abacaba First abcde Second Note In the first sample the first player has multiple winning moves. But the minimum one is to cut the character in position. In the second sample the first player has no available moves.

G. Sharti time limit per test: 5 seconds : standard : standard During the last 4 hours Hamed and Malek spent all their time playing "Sharti". Now they are too exhausted to finish the last round. So they asked you for help to determine the winner of this round. "Sharti" is played on a n n board with some of cells colored white and others colored black. The rows of the board are numbered from top to bottom using number 1 to n. Also the columns of the board are numbered from left to right using numbers 1 to n. The cell located at the intersection of i-th row and j-th column is denoted by (i, j). The players alternatively take turns. In each turn the player must choose a square with side-length at most k with its lowerright cell painted white. Then the colors of all the cells in this square are inversed (white cells become black and viceversa). The player who cannot perform a move in his turn loses. You know Hamed and Malek are very clever and they would have played their best moves at each turn. Knowing this and the fact that Hamed takes the first turn, given the initial board as described in the, you must determine which one of them will be the winner. In this problem the initial board is specified as a set of m rectangles. All cells that lie inside at least one of these rectangles are colored white and the rest are colored black. In the first line of three space-spereated integers n, m, k (1 k n 10, 1 m 5 10 ) follow, denoting size of the board, number of rectangles and maximum size of the turn square during the game, respectively. In i-th line of the next m lines four space-seperated integers a, b, c, d (1 a c n, 1 b d n) are given meaning that i-th rectangle determining the initial board is a rectangle with upper-left cell at (a i, b i) and lower-right cell at (c, d ). i i If Hamed wins, print "Hamed", otherwise print "Malek" (without the quotes). 9 4 i i i i i i i i 5 1 1 1 3 3 4 4 Malek 1 5 7 3 4 5 6 1 1 4 5 9 9 8 6 1 10 1 4 1 4 Hamed