poj3347 Kadj Squares (computational geometry)

Source: Internet
Author: User
Tags integer numbers

D-kadj SquaresTime limit:2000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64 U SubmitStatus

Description

In this problem, 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 this their sides make degrees WI Th x and y axes, and one of their vertices is on y=0 line. Let bi is the x coordinates of the bottom vertex of Si. First, put S1 such that it left vertex lies on x=0. Then, put S1, (I > 1) at minimum bi such

    • bi > bi-1 and
    • The interior of Si does not has intersection with the interior of S1 ... S I-1.

The goal is to find which squares was visible, either entirely or partially, when viewed from above. In the example above, the squares s1, s2, ands4 has this property. More formally, Si was visible from above if it contains a point p, such this no square other than si< /c5> intersect the vertical half-line drawn from p upwards.

Input

The input consists of multiple test cases. The first line of all test case is n (1≤ n ≤50), the number of squares.  The second line contains nintegers between 1 to $, 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 o Rder, separated by blank characters.

Sample Input

43 5 1 432 1 20

Sample Output

1 2 41 3

Test instructions: Change the length of the different n squares, oblique 45 degrees in order flat on the axis, as far as possible on the left but can not jump out of x=0,

Ask from the top down, which squares are visible.

1, if the former i-1 a square position are determined, then you can let the first square and the first i-1 square each

Calculates the value of the left coordinate if it is dependent on it, and then takes one of the largest squares.

   Position of the left endpoint.

2, for J<i Square, if I's side grew up in J then the most right part of J can not be more than the left side of I

The most left-most visible part of I will not be smaller than the J-right end point.

3, through the 2nd step screening, the most left can see the endpoint than the right can see the end of large or equal to remove, left

The next is what is required.

Note: In order to avoid floating-point arithmetic, the square root 2 is about to drop, the code of side length actually refers to side length/square root 2, can also

The problem is understood as projecting the square onto the x-axis.

#include <iostream>#include<string.h>#include<math.h>#include<algorithm>using namespacestd;structsa{intL,r,len;} data[ -];intMain () {intN;  while(cin>>n&&N) {memset (data,0,sizeof(data));  for(intI=0; i<n;i++) {cin>>Data[i].len;  for(intj=0; j<i;j++) DATA[I].L=max (Data[i].l,data[j].r-abs (data[i].len-Data[j].len)); /Seek the left endpoint, according to the nature of isosceles right triangle can be launched relationship DATA[I].R=data[i].l+2*Data[i].len; }         for(intI=0; i<n;i++)        {             for(intj=0; j<i;j++)            {                if(data[j].r>DATA[I].L)//updatable {if(data[j].len<Data[i].len) DATA[J].R=data[i].l;//to the right, the left side of the block.ElseDATA[I].L=data[j].r;//the right side of the left side of the block}} }         for(intI=0; i<n;i++)        {            if(data[i].l<DATA[I].R) cout<<i+1<<" "; } cout<<Endl; }    return 0;}

poj3347 Kadj Squares (computational geometry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.