Friday, November 21, 2008

ACM ICPC Philippines 2008: Sample Problem for Practice Session

2nd Philippine National Inter-Collegiate Programming Competition
(ACM Philippines 2008)
22 November 2008, Cebu City

Sample Problem: “Happy Jumper”
Input File:


A sequence of positive n integers is called a “happy jumper” if the absolute values of the difference between successive elements take on all possible values through n – 1.

For instance,

1 4 2 3

is a happy jumper, because the absolute differences are 3, 2, 1, respectively.

The definition implies that any sequence of a single integer is a happy jumper.


Write a program to determine whether each of a number of sequences is a happy jumper.


Each line of input contains an integer n < 3,000 followed by n integers representing the sequence.


For each line of input generate a line of output saying “Happy” or “Not happy”.

Sample Input Sample Output

4 1 4 2 3 Case 1: Happy
5 1 4 2 -1 6 Case 2: Not Happy


No comments: