poj 3347 Kadj Squares(计算几何)

本文概述了AI音视频处理领域的关键技术,包括视频分割、语义识别、自动驾驶、AR、SLAM等,并探讨了其在实际应用中的作用。
Kadj Squares
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 2194 Accepted: 869

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 positivex-y quarter of the plane, such that their sides make 45 degrees withx and y axes, and one of their vertices are on y=0 line. Letbi be the x coordinates of the bottom vertex of Si. First, put S1 such that its left vertex lies onx=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 ofS1...Si-1.

The goal is to find which squares are visible, either entirely or partially, when viewed from above. In the example above, the squaresS1, S2, and S4 have this property. More formally,Si is visible from above if it contains a point p, such that no square other thanSi intersect the vertical half-line drawn from p upwards.

Input

The input consists of multiple test cases. The first line of each test case isn (1 ≤ n ≤ 50), the number of squares. The second line containsn integers between 1 to 30, where the ith number is the length of the sides ofSi. 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.

Sample Input

4
3 5 1 4
3
2 1 2
0

Sample Output

1 2 4
1 3

Source


题意:给出n个正方形的边长,按图中所示放置,且必须按给出的顺序,正方形必须紧贴
题解:直接将给出的边长 x 扩大根号2倍,那么最左的点到最右的点的距离就是2x了,然后暴力判断处理一些整数关系就可以了

#include<stdio.h>
struct point{
    int l,r,len;
}p[58];
int MAX(int a,int b)
{
    return a>b?a:b;
}
int myabs(int x)
{
    return x<0?-x:x;
}
int main()
{
    int n,i,j,flag;

    while(scanf("%d",&n)&&n)
    {
        for(i=0;i<n;i++)
        {
            scanf("%d",&p[i].len);
            p[i].l=0;
            for(j=0;j<i;j++)
                p[i].l=MAX(p[i].l,p[j].r-myabs(p[j].len-p[i].len));
            p[i].r=p[i].l+2*p[i].len;
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<i;j++)
                if(p[i].l<p[j].r)
                {
                    if(p[i].len>p[j].len) p[j].r=p[i].l;
                    else p[i].l=p[j].r;
                }
        }
        for(flag=i=0;i<n;i++)
        {
            if(p[i].l<p[i].r)
            {
                if(flag) printf(" ");
                printf("%d",i+1);
                flag=1;
            }
        }
        printf("\n");
    }

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值