POJ 3347 特殊方法

简介:

题意:给予n个正方形,要求45°角放置,最左边的正方形紧贴Y轴,所有的正方形的下面的端点都在X轴上。然后按照正方形不能交错但要尽可能的挨着的原则,摆放,最后输出从上往下看能看到的正方形的编号。

这题先可以扩大√2倍。

1确定正方形左端点的位置的方法:遍历之前的正方形求与之前每个正方形挨着的最大值。

2根据左端点坐标求出右端点坐标。

3将正方形看作线段,如果这条线段存在没有被其他线段遮挡的区域那么这个正方形可以输出。

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct sq
{
    int l,r,len;
};
int getl(sq a,sq b)
{
    if(a.len<=b.len)
        return b.l+b.len+a.len;
    else
        return b.r+b.len-a.len;
}
int main()
{
    int n;
    sq data[55];
    while(~scanf("%d",&n),n)
    {
        for(int i=0; i<n; i++)
        {
            scanf("%d",&data[i].len),data[i].l=0;
            for(int j=0; j<i; j++)
                data[i].l=max(getl(data[i],data[j]),data[i].l);
            data[i].r=data[i].l+2*data[i].len;
        }
        for(int i=1; i<n; i++)
            for(int j=0; j<i; j++)
            {
                if(data[i].len<data[j].len&&data[i].l<data[j].r)
                    data[i].l=data[j].r;
                else if(data[i].len>data[j].len&&data[i].l<data[j].r)
                    data[j].r=data[i].l;
            }
        for(int i=0; i<n; i++)
            if(data[i].l<data[i].r)
                printf("%d ",i+1);
        printf("\n");
    }
    return 0;
}


目录
相关文章
|
容器
POJ 3640 Conformity
POJ 3640 Conformity
55 0
|
存储
|
人工智能 机器学习/深度学习
POJ 1012 Joseph
Joseph Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53862   Accepted: 20551 Description The Joseph's problem is notoriously known.
839 0
poj 1455
Description n participants of > sit around the table. Each minute one pair of neighbors can change their places.
618 0
POJ 2487 Stamps
Description Background Everybody hates Raymond. He’s the largest stamp collector on planet earth and because of that he always makes fun of all the others at the stamp collector parties.
1062 0
|
人工智能
POJ 1936 All in All
Description You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way.
789 0
|
存储 索引