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

Similar documents
Chess Handbook: Course One

Unit. The double attack. Types of double attack. With which pieces? Notes and observations

YourTurnMyTurn.com: chess rules. Jan Willem Schoonhoven Copyright 2018 YourTurnMyTurn.com

Structured Programming Using Procedural Languages INSS Spring 2018

Chapter 1: Positional Play

THE COMPLETE RULES OF TIME-CUBE CHESS

After learning the Rules, What should beginners learn next?

Movement of the pieces

OCTAGON 5 IN 1 GAME SET

If a pawn is still on its original square, it can move two squares or one square ahead. Pawn Movement

All games have an opening. Most games have a middle game. Some games have an ending.

LEARN TO PLAY CHESS CONTENTS 1 INTRODUCTION. Terry Marris December 2004

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

BALDWIN WALLACE UNIVERSITY 2013 PROGRAMMING CONTEST

CHESS IN SCHOOLS DO WE TEACH IT THE RIGHT WAY?

DELUXE 3 IN 1 GAME SET

OPENING IDEA 3: THE KNIGHT AND BISHOP ATTACK

Tactics Time. Interviews w/ Chess Gurus John Herron Interview Tim Brennan

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

Welcome to the Brain Games Chess Help File.

GICAA State Chess Tournament

More Adversarial Search

Winning Chess Strategies

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

A1 Problem Statement Unit Pricing

NSCL LUDI CHESS RULES

The game of Paco Ŝako

The Basic Rules of Chess

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

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

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

Boulder Chess. [0] Object of Game A. The Object of the Game is to fill the opposing Royal Chambers with Boulders. [1] The Board and the Pieces

Math Circles 9 / 10 Contest Preparation I

John Griffin Chess Club Rules and Etiquette

Triple Challenge.txt

Which Rectangular Chessboards Have a Bishop s Tour?

ChesServe Test Plan. ChesServe CS 451 Allan Caffee Charles Conroy Kyle Golrick Christopher Gore David Kerkeslager

An End Game in West Valley City, Utah (at the Harman Chess Club)

a b c d e f g h i j k l m n

Analyzing Games: Solutions

LESSON 2: THE INCLUSION-EXCLUSION PRINCIPLE

Its topic is Chess for four players. The board for the version I will be discussing first

arxiv: v2 [cs.ai] 15 Jul 2016

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

Chess Puzzle Mate in N-Moves Solver with Branch and Bound Algorithm

BAPC The Problem Set

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


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

Chess Rules- The Ultimate Guide for Beginners

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

Essential Chess Basics (Updated Version) provided by Chessolutions.com

Upper Primary Division Round 2. Time: 120 minutes

3. Bishops b. The main objective of this lesson is to teach the rules of movement for the bishops.

Freshman Seminar 23j (Spring [2005 ]2006): Chess and Mathematics Preliminary Puzzle

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

Infinite chess. Josh Brunner. May 18, 2018

The Pieces Lesson. In your chess set there are six different types of piece.

A Simple Pawn End Game

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

Problem A. Ancient Keyboard

Here is Part Seven of your 11 part course "Openings and End Game Strategies."

Problem A. First Mission

2006 Canadian Computing Competition: Junior Division. Sponsor:

Adversary Search. Ref: Chapter 5

UKPA Presents. March 12 13, 2011 INSTRUCTION BOOKLET.

Introduction 5 Algebraic Notation 6 What s So Special About the Endgame? 8

Presentation by Toy Designers: Max Ashley

If a word starts with a vowel, add yay on to the end of the word, e.g. engineering becomes engineeringyay

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

Chess, a mathematical definition

CHESS SOLUTION PREP GUIDE.

State Math Contest (Junior)

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

Chess for Kids and Parents

Project 1: A Game of Greed

Advanced Strategy in Spades

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

Chapter 1. Probability

Stat 155: solutions to midterm exam

Novice Nook. When You're Winning, It's a Whole Different Game. Dan Heisman

Separation Numbers of Chessboard Graphs. Doug Chatham Morehead State University September 29, 2006

Chess and Python revisited

GROUP ROUND INSTRUCTIONS

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

12 Special Moves - Stalemate, Pawn Promotion, Castling, En Passant capture

Suggested by Joshua L. Mask. Written by Ken Mask, MD. Illustrated by Simmie Williams

Essentials. Week by. Week

Google DeepMind s AlphaGo vs. world Go champion Lee Sedol

Lecture 6: Latin Squares and the n-queens Problem

Crossing Game Strategies

Lecture 2: Sum rule, partition method, difference method, bijection method, product rules

Pascal Contest (Grade 9)

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?

Problem F. Chessboard Coloring

N-Queens Problem. Latin Squares Duncan Prince, Tamara Gomez February

Figure 1: The Game of Fifteen

Final Project: Reversi

STATION 1: ROULETTE. Name of Guesser Tally of Wins Tally of Losses # of Wins #1 #2

Lower Fall Programming Contest 2017

Transcription:

Westminster College 01 High School Programming Contest October, 01 Rules: 1. There are six questions to be completed in two and 1/ hours.. All questions require you to read the test data from standard input and write results to standard output. You should not use files for input or output.. The allowed programming languages are C++ and Java.. All programs will be re-compiled prior to testing with the judges data.. Programming style is not considered in this contest. You are free to code in whatever style you prefer. Documentation is not required. 6. Judges decisions are final. No cheating will be tolerated.

01 Westminster High School Programming Contest 1 Problem A: The n + 1 problem The n + 1 problem is a very interesting mathematical problem which goes as follows: start with any positive integer n, and then do one of the following: 1. if n is even, replace n with n/.. if n is odd, replace n with n + 1. So, if you start with n =, you would first replace it with / = 19. Next you would replace 19 with (19) + 1 =. This, in turn, would be replaced by 9, which is replaced by, and so on. That s it. So where s the very interesting part you ask? Well, for every starting positive number n that s ever been tried, this procedure eventually generates 1. Using the example above, the series of numbers generated is 19 9 11 17 6 1 0 0 10 16 1 And the REALLY interesting thing about it is that no one has yet been able to prove that this will ALWAYS be the case for any positive integer n (the problem was first posed by L. Collatz in 197 and remains one of the most famous unanswered questions in mathematics). Now, needless to say, I m not asking you to prove the n + 1 problem, but I am asking you to implement it. The input file will consist of multiple test cases. Each case consists of a single positive integer n. The maximum value for n will be 100,000,000 (NOTE: C++ users, you ll want to use the type long long for n, not int or long; Java users should use the type long). A line containing a single 0 will terminate input. For each test case, output the case number followed by the number of times you had to replace the starting number until you get to 1. 10 0 Case 1: 1 Case : 1 Case : 10

01 Westminster High School Programming Contest Problem B: I m Asking You to Check, Mate The game of chess is played on an board, and each side has 16 pieces consisting of kings, queens, rooks, bishops, knights and pawns (we ll ignore pawns for this problem). Each piece has a unique way to move on the board as follows: the queen is the most powerful piece, and can move to any square in the same row, column or diagonal which it is currently on, as shown in the first figure below: the queen on square (,) can move to squares (,), (,7), (,) and a host of others ( all together). This figure also shows how the king moves. It too can move in any direction, but only one square at a time. The rook can only move in the same row or column it is currently on, and the bishop can only move on a diagonal which is currently on (see figure ). The strangest piece is the knight, which moves in an L-shaped manner squares in any direction along its row or column, and then 1 square in a direction at right angles to this (see figure we will use N for a knight, since K is already used for the king). 7 6 1 K Q 1 6 7 Figure 1 7 6 1 R B 1 6 7 Figure 7 6 1 N 1 6 7 Figure If any of your opponent s pieces are on a square that one of your pieces can move to, it is under attack, meaning that your piece can move to that square and remove the opposing piece from the board. The object of a game of chess is to checkmate the opposing king, which occurs when 1. the opposing king is under attack (i.e., one of you pieces could move to the king s position), and. every possible square the king could move to is also under attack. For example, the opposing king (the circled K) in Fig below is checkmated: it is currently under attack by your queen, and can t move to any safe square because of your queen, rooks and the knight. The king in Fig is not checkmated, as it can move safely to squares (, ) or (, 6) since none of your pieces are attacking either of those squares. 7 6 1 Q R K N R 1 6 7 Figure 7 6 1 Q R K N 1 6 7 Figure

01 Westminster High School Programming Contest For this problem, you will read in the positions of several of your pieces and the position of the opposing king and must determine whether or not the opposing king has been checkmated. There will be multiple test cases. Each test case will start with a line containing a positive integer n indicating the number of total pieces on the board (n-1 of your pieces and 1 opposing king). Following that will be n lines, each containing a single character following by a pair of integers. The single character identifies the type of piece (either K, Q, R, B or N ) and the pair of integers specifies the column and row location of the piece. The opposing king will always be the last piece specified. Unlike real chess, there can be any number of your kings, queens, rooks, bishops and knights on the board, but there will always be only one opposing king. You may also assume that none of your pieces is next to the opposing king, and that no piece gets in the way of any other piece. A single 0 will terminate input. The two sample inputs below correspond to figures and above. For each test case, output the case number followed by either Yes if the king is checkmated, or No m if the king is not checkmated and has m safe squares to move to. Q R 1 R 7 7 N 6 K 6 Q R 7 7 N 6 K 6 0 Case 1: Yes Case : No

01 Westminster High School Programming Contest Problem C: It All Adds Up The number 1 can be written as the sum of consecutive positive integers in two different ways: 1 = +6 and 1=16+17+1. Hey wait, there s a third way! 1 = 6+7++9+10+11. Neat! Sounds like an idea for a programming problem! The input file will consist of multiple test cases. Each case consists of a single positive integer n. The maximum value for n will be 100,000. A line containing a single 0 will terminate input. For each test case, output the case number and an integer m indicating the number of ways which the value of n for that problem can be broken down to a sum of consecutive integers (we ll call each of these sums a partition). After this, output the m partitions, one per line, in the form a b where a + (a + 1) + (a + ) + + b is one of the ways to get n. the partition with the smallest a value first, then the next smallest, etc. 1 0 Case 1: 6 11 16 1 6 Case : 0 Case : 1 10

01 Westminster High School Programming Contest Problem D: Scoooooooooooooore! You work for an on-line newspaper called The Daily Blab and have one and only one job: to post football scores once the games are over. You have an assistant at each game who tweets every time some team scores. To keep things simple (and within the 10 character limit), your assistant only tweets the first letter of the scoring team s name, and what they did to score. In (American) football there are five ways to score points: a touchdown, worth 6 points; an extra point, worth 1 point; a two-point conversion worth (what else) points; a field goal, worth points; and a safety, worth points (actually, there s a sixth way as well do any of you know what it is?). So if the Steelers are playing the Ravens, a tweet might look like S T, meaning the Steelers scored a touchdown, or R F meaning the Ravens scored a field goal (no matter how unlikely). An E, C and an S are used to indicate an extra point, a two-point conversion and a safety. After the game is over you can use these tweets to determine the final score, which you then post. For example, if you got the tweets S T, S E, R F, S F, S S, you would post Steelers 1, Ravens. The input file will consist of multiple games. The input file starts with an integer n indicating the number of games. Each game starts with a line containing the team names, which always start with different letters. Following this will be the tweets, one per line. Each tweet will consist of two characters separated by a space. For all but the last tweet the first character will be one of the two starting characters for the team name, and the second character will be either T, E, C, F or S. All characters will be uppercase. The last tweet in each game will be $ $ indicating the game is over. For each game output the game number followed by the winning teams name and score, and the losing teams name and score, each separated by a single space. There will never be a tie game. Steelers Ravens S T S E R F S F S S $ $ Cowboys Redskins R T R T R T R T $ $ Game 1: Steelers 1 Ravens Game : Redskins Cowboys 0

01 Westminster High School Programming Contest 6 Problem E: And Speaking of Tweets You are all well aware of the Twitter phenomenon, and the fact that tweets can only be 10 characters long. You ve just been promoted to Head Twit at a spinoff company called Twitter Lite which only allows 0 characters per tweet. Your job is to enforce this limit. You read each users tweets and truncate them if they go over the 0 character limit. To make up for their smaller tweet size, Twitter Lite has a somewhat more lenient policy as to what counts as a character, only counting non-whitespace characters towards the total (i.e., they don t count spaces, tabs or new-line characters). The input file will consist of multiple test cases. The first line will contain an integer n indicating the number of test cases. Each test case will be on a single line and will contain only alphanumeric characters, punctuation and spaces. There will never be two or more consecutive spaces in any line. For each test case output the first message as written up to and including the 0th character (not counting spaces). If the message is less than 0 characters to start with, just output the message in its entirety. This is a short tweet that won t get truncated. This tweet contains 70 characters so it will get truncated before it gets to the end. This is a short tweet that won t get truncated. This tweet contains 70 characters so it will get truncated b Reading in Lines C++: To read in an entire line into a string variable s use the global function getline() found in the string library. #include <string> using namespace std;... string s;... getline(cin,s); Java: To read in an entire line into a String variable s, use the nextline method of a Scanner object. import java.util.scanner;... Scanner in = new Scanner(System.in); String s;... s = in.nextline();

01 Westminster High School Programming Contest 7

01 Westminster High School Programming Contest Problem F: You ve Got Nothing to Hit but the Heights Brock Buster is a big-time Hollywood director who s looking for three actors for his next film to play the roles of the crotchety yet loveable grandfather, the hard-driven and neglectful father, and the winsome but hard-as-nails son. Brock has a specific image in his head about the relative heights for these roles. He wants the grandfather to be inches taller than the father, who in turn should be 6 inches taller than the son. This is a MUST (along with the fresh papaya-and-sprouts smoothie Brock demands each morning before filming). You re in charge of the casting call, and you figure the first thing you have to do is to satisfy Brock s height requirements. You have the portfolios of everyone who wants to audition, and from this you want to pull out all the groups of three actors who have the appropriate heights. This has turned out to be a little harder than you planned, so you decide to write a program to do it for you (Wow! Hollywood casting agent AND computer programmer you must be pretty talented!). The input file will consist of multiple test cases. Each case starts with an integer n 00 indicating the number of actors auditioning for the rolls. After this are n lines of the form name height where name is the name of the actor and height is the actor s height in inches. Each name will be a single word and no two actors will have the same height. A line with a single zero will terminate input. For each test case, output the case number on a single line, following by one line for each appropriate group of actors. Within each group, print the tallest person s name first, followed by the name of the next tallest and then the shortest person s name. Separate each name with a single blank. Print the tallest group first, i.e. the group with the tallest first person, followed by the second tallest group, etc. Follow the format shown below.

01 Westminster High School Programming Contest 9 Ford 61 Depp 69 DiCaprio 6 Hanks 71 Pitt 70 Statham 6 Smith 7 Chan 67 Nicholson 70 Willis 6 Crowe 66 McGregor 6 Bale 0 Stallone 6 Freeman 9 0 Case 1: Smith Depp DiCaprio Pitt Chan Ford Case : Case : Freeman Stallone Bale