Description
In this problem, you are given a sequence S1, S2, ..., Sn of squares of different sizes. The sides of the squares are integer numbers. We locate the squares on the positive x-y quarter of the plane, such that their sides make 45 degrees with x and y axes, and one of their vertices are on y=0 line. Let bi be the x coordinates of the bottom vertex of Si. First, put S1 such that its left vertex lies on x=0. Then, put S1, (i > 1) at minimum bi such that
- bi > bi-1 and
- the interior of Si does not have intersection with the interior of S1...Si-1.
The goal is to find which squares are visible, either entirely or partially, when viewed from above. In the example above, the squares S1, S2, and S4 have this property. More formally, Si is visible from above if it contains a point p, such that no square other than Si intersect the vertical half-line drawn from p upwards.
Input
The input consists of multiple test cases. The first line of each test case is n (1 ≤ n ≤ 50), the number of squares. The second line contains n integers between 1 to 30, where the ith number is the length of the sides of Si. The input is terminated by a line containing a zero number.
Output
For each test case, output a single line containing the index of the visible squares in the input sequence, in ascending order, separated by blank characters.2
Source
Solving
수열 S1, S2, ..., Sn이 주어진다. Si는 i번째 정사각형의 한 변의 길이이다. 각 정사각형들을 45도 기울여 왼쪽으로 타이트하게 붙여 위에서 내려다 봤을 때 눈에 보이는 정사각형의 번호를 구하라.
'problem solving > Problem Solving' 카테고리의 다른 글
Vase collection (0) | 2008.10.16 |
---|---|
Bridging signals (0) | 2008.10.16 |
Party at Hali-Bula (0) | 2008.10.12 |
Barbara Bennett's Wild Numbers (0) | 2008.10.12 |
Cake Cutting (0) | 2008.10.10 |