JAG Winter Camp ’08 Day 2 Problem E Subdividing a Land

Slides:



Advertisements
Similar presentations
Spring 2013 Advising Starts this week! CS2710 Computer Organization1.
Advertisements

Copyright © Cengage Learning. All rights reserved.
ECIV 201 Computational Methods for Civil Engineers Richard P. Ray, Ph.D., P.E. Error Analysis.
Continued Fractions in Combinatorial Game Theory Mary A. Cox.
Notes, part 4 Arclength, sequences, and improper integrals.
Rational and Irrational
11.1 and 11.2 Radicals Goal(s): 1.To find the square roots of perfect squares, perfect square radicands and estimate the roots of irrational numbers 2.Determine.
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM.
6.1 The Fundamental Property of Rational Expressions.
Infinite Geometric Series
8/24/2015 V. J. Motto 1 Chapter 2: Review – Quadratic Function V. J. Motto M110 Modeling with Elementary Functions.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 3 Computing with Numbers.
The Discriminant Check for Understanding –
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Chapter 31.
THE NATURE OF GROWTH Copyright © Cengage Learning. All rights reserved. 10.
The Real Number System. Real Numbers The set of all rational and the set of all irrational numbers together make up the set of real numbers. Any and all.
VOCABULARY. The set {0, 1, 2,….} Whole Numbers VOCABULARY Lines and sets that never end continue to… Infinity.
Information Representation (Level ISA3) Floating point numbers.
9.1 Sequences. A sequence is a list of numbers written in an explicit order. n th term Any real-valued function with domain a subset of the positive integers.
MATH 224 – Discrete Mathematics
Round-off Errors.
EXAMPLE 2 Rationalize denominators of fractions Simplify
Round-off Errors and Computer Arithmetic. The arithmetic performed by a calculator or computer is different from the arithmetic in algebra and calculus.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter.
MECN 3500 Inter - Bayamon Lecture 3 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Section 9.1 Finding Roots. OBJECTIVES Find the square root of a number. A Square a radical expression. B.
1. √49 2. –√144 Lesson 4.5, For use with pages
Write the radical expression in simplest form.
Warm-Up Change each decimal to a fraction:
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 3.
5 – 2: Solving Quadratic Equations by Factoring Objective: CA 8: Students solve and graph quadratic equations by factoring, completing the square, or using.
Numerical Analysis CC413 Propagation of Errors.
Properties of Real Numbers
Solve each equation and check the solution. 08 September 2015 Warm-Up.
Section 1Chapter 1. 1 Copyright © 2012, 2008, 2004 Pearson Education, Inc. Objectives Basic Concepts Write sets using set notation. Use number.
CS104:Discrete Structures Chapter 2: Proof Techniques.
STROUD Worked examples and exercises are in the text Programme 10: Sequences PROGRAMME 10 SEQUENCES.
Chapter 4 With Question/Answer Animations 1. Chapter Summary Divisibility and Modular Arithmetic - Sec 4.1 – Lecture 16 Integer Representations and Algorithms.
Call the Feds! We’ve Got Nested Radicals! Alan Craig.
Numerical Analysis CC413 Propagation of Errors. 2 In numerical methods, the calculations are not made with exact numbers. How do these inaccuracies propagate.
Module 2.2 Errors 03/08/2011. Sources of errors Data errors Modeling Implementation errors Absolute and relative errors Round off errors Overflow and.
CSE 330: Numerical Methods. What is true error? True error is the difference between the true value (also called the exact value) and the approximate.
11.1 Sequences. A sequence is a list of numbers written in an explicit order. n th term Any real-valued function with domain a subset of the positive.
Copyright © Cengage Learning. All rights reserved. Fundamentals.
Algorithm Analysis 1.
Trigonometric Identities
Real Numbers and Their Properties
Module XIII, Lesson 3 Online Algebra
Equations Quadratic in form factorable equations
1.1: Objectives Properties of Real Numbers
EXAMPLE 2 Rationalize denominators of fractions Simplify
Index, exponential, power
Some Basics for Problem Analysis and Solutions
Looping and Repetition
A quadratic equation is written in the Standard Form,
Chapter 1 Section 1.
Precalculus Mathematics for Calculus Fifth Edition
Rational and Irrational
Copyright © Cengage Learning. All rights reserved.
Copyright © 2017, 2013, 2009 Pearson Education, Inc.
Copyright © Cengage Learning. All rights reserved.
Chapter 9 Section 5.
Chapter 4 Sequences.
Equations Quadratic in form factorable equations
Number Sets.
Irrational Numbers.
Aim: What is the nature of the roots of a quadratic equation?
Solve Quadratic Equations by Finding Square Roots Lesson 1.5
Rational Numbers and Irrational Numbers
Presentation transcript:

JAG Winter Camp ’08 Day 2 Problem E Subdividing a Land ACM-ICPC Japanese Alumni Group

About the Problem Original problem by T. Yoshino Sample Solution by T. Yoshino, Y. Hirano Problem Statement by T. Yoshino Presentation by T. Yoshino

Contest Result 14 submits during the contest Only 1 team was accepted At 234 min. (__________) This is the corrected result, as we had a ‘%lld’ problem

Overview of the Problem From a a-meter square, take n b-meter squares a, b, n are integers But the total ratio must not exceed 50% The residential area less than 50% becomes dead space Minimize the dead space! Not by percentage, but area If we calculate dead space by percentage, it can be as smaller as we want simply by increasing the denominator This leads to divergence to infinity !!

Overview of the Problem a meter(s) Total area of must not exceed 50% More than or equal to 50% of must be retained Minimize dead space Dead space = exceeding 50% a b b

Solution From the percentage constraint, And want to minimize: Actually there are two cases to consider: These two equations cover all cases, so no more cases to be concerned

This is Not a Packing Problem Thanks to the 50% limit, we can always take n squares From the constraint, Apparently, a-meter square can contain b-meter squares

Case 1: The equation can be factorized into: This equation has integer solutions only if 2n is a perfect square of a certain integer Let m be this integer, the minimum solution is apparently (a, b) = (m, 1).

Case 2: This is the equation well-known as “Pell’s equation” : This equation always has (infinitely many) answers whenever N is not a perfect square (Lagrange, ca. 1766) So these two cases cover all inputs

Never Perform a Naïve Search! Sometimes solutions of the equation becomes very huge For example, the minimum solution of is (x, y) = (1766319049, 226153980) As stated in the problem, the solution of each test case is less than 263 Actually, you have to totally inspect 8.92×1018 cases for this problem!!

So How to Solve the Equation? Pell’s equation can be solved by calculating the convergent of continued fraction of Intuitively, this is to calculate a fraction x / y that approximates The solution is the case where the fraction approaches to sufficiently

Continued Fraction A real number ω can be represented by a positive integer sequence [a0; a1, a2, …] where An irrational number has (only one) infinite continued fraction representation A rational number has a finite sequence

Calculating the Convergent The next algorithm illustrates how to calculate the convergent [a0; a1, …] (of ) First, let Let , the largest integer less than or equal to ωn Calculate ωn+1 by the next equation: Repeat these steps

From a Continued Fraction To a Rational Number Suppose we take the first (n+1) elements of the convergent Let the elements be [a0; a1, …, an] Then, the sequence expresses a rational number pn+1 / qn+1 where

Some Theorems About the Solution of Pell’s Equation There are some theorems regarding the existence of solutions of the equation So basically, we have just to calculate the sequences pn and qn until the solution is found

Normal Floating-Point Number Is Not Appropriate for This Purpose Naïve implementation of the former algorithm requires multiprecision number Underflow error becomes a problem in the calculation of ωn+1 Since ωn - an becomes nearly 0 This can lead to infinite loop One of teams tried this and got a Runtime Error Simply avoid that!

Solution Techniques Actually, the following fact is known: By substituting this to the equation for ωn+1, we get: And from Theorem 4,

How Much Precision We Need to Calculate?

How Much Precision We Need to Calculate? (Cont’d) So gn, hn, an fit into int’s No need to care for overflows pn, qn are obviously growing as n increases, so use long long for them From the problem statement, it is guaranteed that the answer never exceeds 263

Speed Up Technique Actually, holds So no need to calculate RHS of the equation every time Or, this relation can be used to bound the range of RHS value of the equation Just break a loop once hn becomes 1 But be aware that hn contains an absolute value Post-processing needed when RHS=-1 (p’, q’) is the minimum answer for RHS=+1, where

Some Interesting Properties of Pell’s Equation Consider a quadratic field LHS of Pell’s Equation is a norm on the field Let α1 be the minimum solution, then for all integer k ≧ 0, α1k is also a solution Actually, all solution of the Pell’s equation can be represented as above

About Judge Data As you will expect, we have prepared the data which does exhaustive search Total 6,921 cases Maximum value of solution is at n = 6621 (a, b) = (8987289718054858751, 78100164792027200) These are less than 263 = 9223372036854775808

Judges’ Solution By T. Yoshino By Y. Hirano Both will do 54 lines in C++ (removed comments / unused code) The core loop can be written in ~10 lines. Solves the judge data in <1 sec By Y. Hirano 132 lines in C++ Naïve calculation of a convergent on a field Solves the judge data in about 3 sec. Both will do

References Pell’s Equation in Wikipedia History and Solution Techniques Also see Continued Fraction Pell Equation in Wolfram MathWorld

Any Questions?