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;
}
时间: 2024-10-27 04:00:45

POJ 3347 特殊方法的相关文章

POJ题目分类

初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      (4)递推.      (5)构造法.(poj3295)      (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996) 二.图算法:      (1)图的深度优先遍历和广度优先遍历.      (2)最短路径算法(dijkstra,bellman-ford

POJ:DNA Sorting 特殊的排序

Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the letter sequence ``DAABEC'', this measure is 5, since D is greater than four letters to

poj 1456 Supermarket:贪心, 并查集

链接: http://poj.org/problem?id=1456 题目: Description A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the

poj 1703 Find them, Catch them:种类并查集

链接: http://poj.org/problem?id=1703 题目: Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22289   Accepted: 6648 Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up

poj 2912 Rochambeau

链接: http://poj.org/problem?id=2912 题目: Description N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is the judge. The rest children are divided into three groups (it is possible that some group is empty). You don't k

poj 1659 Frogs&#039; Neighborhood

题目链接: http://poj.org/problem?id=1659 类型: 贪心,Havel-Hakimi定理 题目: Description 未名湖附近共有N个大小湖泊L1, L2, ..., Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤ i ≤ N).如果湖泊Li和Lj之间有水路相连,则青蛙Fi和Fj互称为邻居.现在已知每只青蛙的邻居数目x1, x2, ..., xn,请你给出每两个湖泊之间的相连关系. Input 第一行是测试数据的组数T(0 ≤ T ≤ 20).每

poj 1094 Sorting It All Out(拓扑排序)

链接: http://poj.org/problem?id=1094 题目: Sorting It All Out Time Limit: 1000MS     Memory Limit: 10000K Total Submissions: 21532     Accepted: 7403 Description An ascending sorted sequence of distinct values is one in which some form of a less-than ope

POJ 1077 Eight:八数码问题

题目链接: http://poj.org/problem?id=1077 题目类型: 隐式图搜索 原题: The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all pac

UVa 10038 / POJ 2575 / ZOJ 1879 Jolly Jumpers (water ver.)

10038 - Jolly Jumpers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=979 http://poj.org/problem?id=2575 http://acm.zju.edu.cn/onlinejudge/showProblem.do?