NCPC 2013 Presentation of solutions



Similar documents
KTH Challenge Solutions. Further Information KTH Challenge April 21, 2013

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Shortest Path Algorithms

Report on the Train Ticketing System

TECHNICAL UNIVERSITY OF CRETE DATA STRUCTURES FILE STRUCTURES

Factoring and Applications

If A is divided by B the result is 2/3. If B is divided by C the result is 4/7. What is the result if A is divided by C?

ML for the Working Programmer

Lecture 13 - Basic Number Theory.

International Journal of Advanced Research in Computer Science and Software Engineering

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Social Media Mining. Graph Essentials

YOU CAN COUNT ON NUMBER LINES

Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

Hierarchical Cluster Analysis Some Basics and Algorithms

DATA OBFUSCATION. What is data obfuscation?

GCE Computing. COMP3 Problem Solving, Programming, Operating Systems, Databases and Networking Report on the Examination.

= = 3 4, Now assume that P (k) is true for some fixed k 2. This means that

SQUARE-SQUARE ROOT AND CUBE-CUBE ROOT

1. Define: (a) Variable, (b) Constant, (c) Type, (d) Enumerated Type, (e) Identifier.

Copy in your notebook: Add an example of each term with the symbols used in algebra 2 if there are any.

MATHCOUNTS TOOLBOX Facts, Formulas and Tricks

Sample Questions Csci 1112 A. Bellaachia

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

Vector storage and access; algorithms in GIS. This is lecture 6

Grade 7/8 Math Circles Fall 2012 Factors and Primes

Chapter 2 Data Storage

Computational Geometry. Lecture 1: Introduction and Convex Hulls

Arrangements And Duality

IMPROVING PERFORMANCE OF RANDOMIZED SIGNATURE SORT USING HASHING AND BITWISE OPERATORS

Grade 7 & 8 Math Circles October 19, 2011 Prime Numbers

EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27

Data Structure [Question Bank]

Adobe Marketing Cloud Data Workbench Monitoring Profile

Task: ASC Ascending Paths

Section 1.1. Introduction to R n

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Florida Math for College Readiness

Algebra I. In this technological age, mathematics is more important than ever. When students

Quick and dirty Mezzo GUI tutorial

Chapter 1. Computation theory

Cloud and Big Data Summer School, Stockholm, Aug Jeffrey D. Ullman

Big Data and Scripting. Part 4: Memory Hierarchies

The finite field with 2 elements The simplest finite field is

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

EVALUATING ACADEMIC READINESS FOR APPRENTICESHIP TRAINING Revised For ACCESS TO APPRENTICESHIP

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Pseudo code Tutorial and Exercises Teacher s Version

5: Magnitude 6: Convert to Polar 7: Convert to Rectangular

Shortest Inspection-Path. Queries in Simple Polygons

Expression. Variable Equation Polynomial Monomial Add. Area. Volume Surface Space Length Width. Probability. Chance Random Likely Possibility Odds

Count the Dots Binary Numbers

CHAPTER SIX IRREDUCIBILITY AND FACTORIZATION 1. BASIC DIVISIBILITY THEORY

Instruction scheduling

U.C. Berkeley CS276: Cryptography Handout 0.1 Luca Trevisan January, Notes on Algebra

Part-Based Recognition

Chapter 3. if 2 a i then location: = i. Page 40

FOPR-I1O23 - Fundamentals of Programming

ALGEBRA I (Common Core)

Data Warehousing und Data Mining

Open Problems in Quantum Information Processing. John Watrous Department of Computer Science University of Calgary

A Study of Crossover Operators for Genetic Algorithm and Proposal of a New Crossover Operator to Solve Open Shop Scheduling Problem

Common Core Unit Summary Grades 6 to 8

Mining Data Streams. Chapter The Stream Data Model

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. !-approximation algorithm.

Category 3 Number Theory Meet #1, October, 2000

Answer: (a) Since we cannot repeat men on the committee, and the order we select them in does not matter, ( )

Notes on Factoring. MA 206 Kurt Bryan

IBM SPSS Direct Marketing 23

APP INVENTOR. Test Review

Access Code: RVAE4-EGKVN Financial Aid Code: 6A9DB-DEE3B-74F

Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA === Homework submission instructions ===

Image Compression through DCT and Huffman Coding Technique

Math Workshop October 2010 Fractions and Repeating Decimals

MACM 101 Discrete Mathematics I

Vocabulary Words and Definitions for Algebra

MAC Sublayer. Abusayeed Saifullah. CS 5600 Computer Networks. These slides are adapted from Kurose and Ross

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

IBM SPSS Direct Marketing 22

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.

Lecture 1: Course overview, circuits, and formulas

Sheet 7 (Chapter 10)

Storing Measurement Data

Cpt S 223. School of EECS, WSU

CONTINUED FRACTIONS AND FACTORING. Niels Lauritzen

College of the Holy Cross CCSCNE 06 Programming Contest Problems

Algebra 2 Chapter 1 Vocabulary. identity - A statement that equates two equivalent expressions.

A Quick Algebra Review

Factor Trees. Objective To provide experiences with finding the greatest common factor and the least common multiple of two numbers.

n 2 + 4n + 3. The answer in decimal form (for the Blitz): 0, 75. Solution. (n + 1)(n + 3) = n lim m 2 1

COS 318: Operating Systems

CSE 4351/5351 Notes 7: Task Scheduling & Load Balancing

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

Binary Heap Algorithms

Approximation Algorithms

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Transcription:

NCPC 2013 Presentation of solutions Head of Jury: Lukáš Poláček 2013-10-05

NCPC Jury authors Andreas Björklund (LTH) Jaap Eldering (Imperial) Daniel Espling (UMU) Christian Ledig (Imperial) Ulf Lundström (KTH) Stefan Pszczolkowski (Imperial) Michał Pilipczuk (UIB) Lukáš Poláček (KTH) Andreas Schuh (Imperial) Fredrik Svensson (Autoliv Electronics) Marc Vinyals (KTH)

G Erase Securely Given binary hard disk content before and after described safe file removal procedure, decide whether it was successful. Solution Insight: Each time the file is overwritten, all of its bits are flipped Odd-th number of overwrite: flips all bits once Even-th number of overwrite: Undoes previous flipping In case of odd number of total overwrites, all bits must appear as if flipped once for the removal to be considered successful. Otherwise, both binary strings must be identical. Author: Ulf Lundström, Andreas Schuh

A Planting Trees Find an optimal planting schedule to minimize the earliest date when all the trees are mature. Insight and Solution Insight: It is optimal to plant the trees in descending order of growth times. Proof: If any two trees are not in this order, then swapping them cannot increase the result. Solution: Sort the trees by decreasing growth times, and output max(position + growth time + 1). Time complexity: O(n log n). Author: Michał Pilipczuk

F Timebomb (1/2) Translate ASCII digits into memory variables Insight and Solution Insight: The code is not known until the input has been read completely. Store the ASCII representation in memory, e.g., matrix of char and compute the number of digits from the string length. Translate the code into a number by using the appropiate power of 10 for each digit and compute the sum of them. Stop if we find an invalid digit. Check if the number is zero modulo 6. But, what if the problem would have allowed 100-digit codes? Author: Stefan Pszczolkowski

F Timebomb (2/2) Alternative solution Compute the sum of the digits. Use the fact that a number is divisible by 6 if it is an even number and the sum of its digits is divisible by 3. Author: Stefan Pszczolkowski

E Virus Replication Find the minimum substring that needs to be changed to turn one string into another. ACCGTCA ACCTTGCA Insight The beginning and end of the two strings should be identical up until the change. Solution First difference from start of strings marks start of change. First difference from end of strings marks end of change. Check that the start of the change is before its end in both strings. Author: Ulf Lundström

D Robert Hood Find the longest distance between any pair of points in a set. Insights and Solution Insight: The interesting points are those in the convex hull of the set. Find the convex hull using a known fast algorithm. Insight: The small integer coordinate range [ 1000, 1000] means that the number of points on the convex hull will be reasonably small. An algorithm with N 2 complexity is sufficiently fast to find the longest distance, i.e. you can examine all possible pairs of points on the hull. Author: Daniel Espling

B Boiling Vegetables Find the minimum number of cuts of vegetables, such that the smallest and largest piece are not very different. Insights and Algorithm Insight: All cut pieces of one vegetable are of the same weight. Loop over all possible candidates for the largest weight piece. For each vegetable piece, calculate how many cuts are needed to get all resulting pieces weigh at most the assumed maximum. Check if they are heavy enough to pass the ratio T from the input. Optimizations: Go to a next candidate for the largest piece if you already cut too many pieces. Complexity is 500N log N. Author: Andreas Björklund and Lukáš Poláček

J Dartboard Calculate the expected score of throwing one dart. Insights and Solution Insight: The problem is radially symmetric after you average the numbers of all pies. Insight: The integral over the radial variable r can be calculated explicitly. The final result can be calculated in constant time as a sum of the scores over six different radius intervals. Alternatively, a sufficiently efficient numerical integration scheme can also be used. Author: Jaap Eldering

C Number Trick (1/2) Given X find numbers A for which moving the first digit to the end of the number is equivalent of multiplying by X. Insight Assume A has n digits and starts with the digit A 0. Moving the first digit to the end then turns it into which should equal A X, so A = (A 10 n A 0 ) 10 + A 0, A X = 10A (10 n+1 1)A 0 A = 10n+1 1 10 X A 0 Author: Ulf Lundström

C Number Trick (2/2) Solution Loop over the number of digits n and all starting digits A 0 to check whether the A obtained from is a valid solution. A = 10n+1 1 10 X A 0 Author: Ulf Lundström

K Cliff Walk Find the furthest reachable point while staying clear of the tide. Insights and Algorithm Find the earliest entry and latest exit time for all squares using the provided formula. Run shortest path from home at t = 0 to all positions. Run shortest path from home at t = 12 to all positions, but backwards in time. Use priority queue to make algorithm run fast. Insight: go through the map and see where arrival time is earlier than departure time. Return the maximum of the distances to these squares. Author: Fredrik Svensson

I Dance Reconstruction (1/2) Given a permutation, find its kth root. Permutation Exponentiation Example: Take permutation to the 20th power A cycle of length 20 breaks down into 20 cycles of length 1 Length 30: 10 3 Length 40: 20 2 Number of cycles: greatest common divisor of 20 and length A solution should merge small cycles back into big ones Author: Lukáš Poláček

I Dance Reconstruction (2/2) Algorithm Decompose input into cycles Insight: When merging m cycles of length l into one cycle of length m l, gcd(m l, k) must be m Example: If k = 20 = 2 2 5 and l = 2, m must be a multiple of 4 If p q k and p l, m must be a multiple of p q. m = gcd(l, k) gives wrong answer Carefully place elements on the big cycle Author: Lukáš Poláček

H Pinball Simulate ball falling down a pinball board Solution Sweep board as ball falls Event queue, sorted by y Events: Add/erase segment, possible ball hit Search tree with segments, sorted by x at current y Query: which segment would the ball hit? Update: add/erase segment Insight: No intersections = order in the tree independent of y Author: Marc Vinyals