ARC 102. A: Pair. B: Ruined Square. DEGwer 2018/09/01. For International Readers: English editorial starts on page 6.

Similar documents
PGSS Discrete Math Solutions to Problem Set #4. Note: signifies the end of a problem, and signifies the end of a proof.

CHAPTER 3. Congruences. Congruence: definitions and properties

THE DIVISION THEOREM IN Z AND R[T ]

Inserting plus signs and adding

Review Solutions, Exam 2, Operations Research

Proof Techniques (Review of Math 271)

Chapter 4. Solving Systems of Equations. Chapter 4

Elementary Properties of the Integers

Solutions to February 2008 Problems

Divisibility = 16, = 9, = 2, = 5. (Negative!)

Algorithms and Data Structures 2016 Week 5 solutions (Tues 9th - Fri 12th February)

CSC 344 Algorithms and Complexity. Proof by Mathematical Induction


One-to-one functions and onto functions

1 True/False. Math 10B with Professor Stankova Worksheet, Discussion #9; Thursday, 2/15/2018 GSI name: Roy Zhao

McGill University Faculty of Science. Solutions to Practice Final Examination Math 240 Discrete Structures 1. Time: 3 hours Marked out of 60

, p 1 < p 2 < < p l primes.

This is a recursive algorithm. The procedure is guaranteed to terminate, since the second argument decreases each time.

a. See the textbook for examples of proving logical equivalence using truth tables. b. There is a real number x for which f (x) < 0. (x 1) 2 > 0.

STEP Support Programme. Hints and Partial Solutions for Assignment 17

Commutative Rings and Fields

HMMT February 2018 February 10, 2018

Section 2.7 Solving Linear Inequalities

Graphic sequences, adjacency matrix

Fall 2017 Test II review problems

P.1 Prerequisite skills Basic Algebra Skills

What can you prove by induction?

Some Review Problems for Exam 1: Solutions

Probability. Part 1 - Basic Counting Principles. 1. References. (1) R. Durrett, The Essentials of Probability, Duxbury.

PUTNAM TRAINING NUMBER THEORY. Exercises 1. Show that the sum of two consecutive primes is never twice a prime.

Linear Programming: Simplex

MATH 114 Fall 2004 Solutions to practice problems for Final Exam

Chapter 1 Review of Equations and Inequalities

Math 110 HW 3 solutions

Finite Mathematics : A Business Approach

Discrete Probability

AQA Level 2 Further mathematics Further algebra. Section 4: Proof and sequences

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

CSE 1400 Applied Discrete Mathematics Proofs

Mathematical Proofs. e x2. log k. a+b a + b. Carlos Moreno uwaterloo.ca EIT e π i 1 = 0.

1 Sequences and Summation

Introduction to Induction (LAMC, 10/14/07)

MI 4 Mathematical Induction Name. Mathematical Induction

CS1800: Mathematical Induction. Professor Kevin Gold

Sums and Products. a i = a 1. i=1. a i = a i a n. n 1

Notice that we are switching from the subtraction to adding the negative of the following term

Generating Permutations and Combinations

1 Basic Combinatorics

Week 4-5: Generating Permutations and Combinations

Solving with Absolute Value

Business Statistics PROBABILITY DISTRIBUTIONS

Writing proofs for MATH 51H Section 2: Set theory, proofs of existential statements, proofs of uniqueness statements, proof by cases

ACO Comprehensive Exam March 20 and 21, Computability, Complexity and Algorithms

Disproof MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Disproof Fall / 16

OEIS A I. SCOPE

Grades 7 & 8, Math Circles 10/11/12 October, Series & Polygonal Numbers

ASSIGNMENT 1 SOLUTIONS

Chapter 3: Polynomial and Rational Functions

Recitation 4: Quantifiers and basic proofs

Unit 2 Polynomial Expressions and Functions Note Package. Name:

Chapter 2. Mathematical Reasoning. 2.1 Mathematical Models

Mathematical Induction

Basics of Proofs. 1 The Basics. 2 Proof Strategies. 2.1 Understand What s Going On

Linear Equations & Inequalities Definitions

2013 University of New South Wales School Mathematics Competition

Quick Sort Notes , Spring 2010

Basic Combinatorics. Math 40210, Section 01 Fall Homework 8 Solutions

Ω R n is called the constraint set or feasible set. x 1

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

Table of Contents. 2013, Pearson Education, Inc.

February 2017 February 18, 2017

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

Common Core Algebra Regents Review

UNCC 2001 Algebra II

Probability & Combinatorics Test and Solutions February 18, 2012

A101 ASSESSMENT Quadratics, Discriminant, Inequalities 1

Section 20: Arrow Diagrams on the Integers

Midterm Exam. CS 3110: Design and Analysis of Algorithms. June 20, Group 1 Group 2 Group 3

Outline Inverse of a Relation Properties of Relations. Relations. Alice E. Fischer. April, 2018

Coach Stones Expanded Standard Pre-Calculus Algorithm Packet Page 1 Section: P.1 Algebraic Expressions, Mathematical Models and Real Numbers

2. Two binary operations (addition, denoted + and multiplication, denoted

MATH 2200 Final Review

Chapter 2: Approximating Solutions of Linear Systems

What is proof? Lesson 1

Semester 2 Final Exam Review Guide for AMS I

CHAPTER 1. REVIEW: NUMBERS

I started to think that maybe I could just distribute the log so that I get:

Ahlswede Khachatrian Theorems: Weighted, Infinite, and Hamming

MATH CSE20 Homework 5 Due Monday November 4

Introduction to Probability. Ariel Yadin. Lecture 1. We begin with an example [this is known as Bertrand s paradox]. *** Nov.

Math 5707: Graph Theory, Spring 2017 Midterm 3

First Digit Tally Marks Final Count

CS 361: Probability & Statistics

Numbers and their divisors

Topic 7 Notes Jeremy Orloff

Appendix A. Jargon. A.1 Strange technical terms

f(x) = lim x 0 + x = lim f(x) =

Lecture 8 : Structural Induction DRAFT

PUTNAM TRAINING MATHEMATICAL INDUCTION. Exercises

Unary negation: T F F T

Transcription:

ARC 102 DEGwer 2018/09/01 For International Readers: English editorial starts on page 6. A: Pair K K/2 K/2 i n t k ; s c a n f ( %d, &k ) ; p r i n t f ( %d\n, ( k / 2 ) ( ( k + 1) / 2 ) ) ; B: Ruined Square using namespace std ; i n t a, b, c, d ; s c a n f ( %d%d%d%d, &a, &b, &c, &d ) ; i n t x = c a, y = d b ; p r i n t f ( %d %d %d %d\n, c y, d + x, a y, b + x ) ; 1

C: Triangular Relationship K a, b, c K 0 K a, b, c K 0 K/2 N K 0 K/2 D: All Your Paths are Different Lengths 2 r L r (r 19 ) 0 2 r 1 1 r + 1 1,..., r + 1 N = r + 1 i i + 1 0 2 i 1 t N X X, X + 1,..., X + 2 t 1 1 1 t = N 1,..., 1 L 2 t 1 2 r t N L 2 t 1 L 2 t 1 E: Stop. Otherwise... 2 t t a + b = t 1 a, b K a, b (a, b) p p (q ) q ( 2 ) O(K) t K/2 1 K/2 (0 1 ) O(K 2 + N) F: Revenge of BBuBBBlesort! a i = (1, 2,..., N) a i 1 < a i < a i+1 3 ( i ) p p 2 : i i 1 i+1 i 1 p i 1 > p i i + 1 p i > p i+1 i 2

i i l + 1, l + 3,..., r 1 l 1, r + 1 [l, r] l + 1, l + 3,..., r 1 (l, l + 2,..., r )(l + 1, l + 3,..., r 1 ) ( ) ( ) ( p ) ( ) p 3

ARC 102 Editorial DEGwer 2018/09/01 A: Pair There are K/2 even numbers and K/2 odd numbers among positive integers up to K. The answer is the product of these values. i n t k ; s c a n f ( %d, &k ) ; p r i n t f ( %d\n, ( k / 2 ) ( ( k + 1) / 2 ) ) ; B: Ruined Square You can compute the coordinates of the reaming points as in the code below: using namespace std ; i n t a, b, c, d ; s c a n f ( %d%d%d%d, &a, &b, &c, &d ) ; i n t x = c a, y = d b ; p r i n t f ( %d %d %d %d\n, c y, d + x, a y, b + x ) ; 1

C: Triangular Relationship When K is odd, a triplet (a, b, c) satisfies the conditions when all of them are divisible by K. It s easy to count such triplets. When K is even, a triplet (a, b, c) satisfies the conditions when all of them are divisible by K, or when all of them are equivalent to K/2 modulo K. We can count such triplets by counting the number of integers up to N that are equivalent to 0 or K/2, modulo K. D: All Your Paths are Different Lengths Solution 1. Let s take the maximum integer r such that 2 r L. First, consider the following graph: There are N = r + 1 vertices numbered 1,..., N. For each i, add two edges from vertex i to vertex i + 1. One of them has length 0, and the other has length 2 i 1. In this graph, there are 2 r paths from vertex 1 to vertex N, and their lengths are 0,..., 2 r 1. What happens if we add an edge of length X from vertex t to vertex N? This way we can add X, X + 1,..., X + 2 t 1 1 to the set of lengths. By adding edges of this type properly (by writing L as a sum of powers of two using binary representation), we can get a desired graph. Solution 2. Suppose that we have a graph G that satisfies the condition for L = X. We ll show how to construct solutions for L = X + 1 and L = 2X using this graph. By repeating these operations properly, we can get a desired graph. L = X + 1 is easy: just add an edge of length X from source to sink to G. L = 2X can be constructed as follows. First, double the lengths of all edges in G. Now the set of lengths is 0, 2,..., 2X 2. Then, add a new vertex to G (it will be the new sink), and add two edges from the old sink to the new sink, with lengths 0 and 1. Now the set of lengths is 0, 1, 2,..., 2X 1, and this is what we want. 2

E: Stop. Otherwise... Let s handle each query independently. combinations of dice such that the sum of no two dice is t. For a fixed value of t, we want to count the number of For simplicity, we say x exists when at least one die shows x. Suppose that t is odd. In this case, the condition can be restated as follows: for each pair (a, b) such that a + b = t, at least one of a or b should not exist. Let s divide integers 1,..., K into pairs, such that the sum of two numbers in each pair is t (and some numbers will be left unpaired). Let p be the number of pairs formed this way. Then, the combination of dice must be of the following form for some integer q: For q pairs, exactly one of the two numbers in the pair exists. For the remaining p q pairs, both numbers don t exist. K 2p numbers are left unpaired: we don t care if these numbers exist. There are ( p q) 2 q ways to choose the set of existing numbers (among paired numbers). After that, the number of ways to distribute the number of occurrences of those numbers among N dice are equal to the number of solutions to the following equation: x 1 + + x q + y 1 +... + y K 2p = N x 1,, x q are positive integers y 1,, y K 2p are non-negative integers Here, x 1,, x q corresponds to the number of occurrences of each existing paired numbers, and y 1,, y K 2p corresponds to the number of occurrences of each unpaired numbers. This is a well-known task and the answer can be represented by a binomial coefficient. By trying all possible values of q, we can count the desired number in O(K) time (assuming that we do some pre-computation and we can get binomial coefficients and powers in O(1)). When t is even, there is an additional constraint that the number of occrrences of t/2 must be either 0 or 1. Try both possibilities, and the remaining part is the same as above. This solution works in O(K 2 + N) time. 3

F: Revenge of BBuBBBlesort! Let s see the operations in the reverse order: we start with a sequence a i = (1, 2,..., N), and we repeat performing operations of the following type: Choose i such that a i 1 < a i < a i+1, and reverse their orders (we call it an operation on i ). We want to check if we can get p this way. First, we ll prove that we can never make operations in two adjacent positions. Suppose that before performing an operation on i, we have performed operations on i 1 or i + 1. If the last operation on i 1 or i + 1 was on i 1, after the opeartion, a i 1 > a i holds. We can never change this inequality: an operation on i 2 only makes a i 1 greater, by the assumption above we don t make operations on i + 1, and operations on other positions obviously don t affest this inequality. Similarly, if the last operation was on i + 1, a i > a i+1 holds, and we can never change this inequality. Thus, we can t make an opeation on i, and we get a contradiction. Let s split the sequence into intervals as follows: a l,..., a r forms an interval if we perform operations on all of l + 1, l + 3,..., r 1, but not on l 1, r + 1. All elements move within these intervals, thus we can consider these intervals independently. From now on, we only considers the interval a l,..., a r. We start with a l,..., a r = l,..., r. How can we change these numbers by performing operations only at l + 1, l + 3,..., r 1? Elements at positions l + 1, l + 3,..., r 1 will never move. Let s call these elements pivots. Consider a non-pivot element x in this interval. From the definition of intervals, this element must move (unless l = r). Suppose that it moves to the left in the first operation that involves this element. Then, after that, this element is always greater than the pivot to the right of it; and it can never move to the right in the future. We can do the same observaion when it moves to the right first. Thus, each non-pivot element keeps moving in the same direction. Consider two non-pivot elements that moves to the left. The relative order of these elements will not change: to change their relative order, we must swap them, but this is impossible because they must keep moving left. We can say the same thing for elements moving right. On the other hand, these conditions are sufficient; we can achieve the goal by repeating operations on consecutive three elements such that ((An element that wants to go right), (pivot), (An element that wants to go left)). To summarize, the conditions are: a l+1, a l+3,..., a r 1 must not change, and other elements must change. If we only consider all elements that moves to the left, they are increasing from left to right. If we only consider all elements that moves to the right, they are increasing from left to right. From the first condition, we can uniquly determine the way to split the sequence into intervals; after that, the remaining two conditions can be checked in linear time. 4