题目:

Description

In this problem, you are given a sequence S1S2, ..., 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 S1S2, 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.

Sample Input

4
3 5 1 4
3
2 1 2
0

Sample Output

1 2 4
1 3

题意:依次给出n个正方形的边长 每个正方形在x轴上呈45°摆放并且尽可能放的紧凑 问从上方看时能看见哪些正方形
思路:对于第i个正方形 判断前i-1个正方形如果和它相交的话左端点的位置 最后取一个最大值作为整个正方形的左端点位置
   对于j<i的正方形 如果i的边长大于j 那么j的最右能看到的部分就不会比i的最左端点大 反之 i的最左能看到的部分就不会比j最右端点小
   再将最左能看到的端点比最右能看到的端点去掉
   为了避免浮点数 将每条边乘上sqrt(2)然后约掉 效果等于将正方形投影到x轴上

代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n; struct node{
int l,r,len;
}kk[maxn]; int main(){
while(~scanf("%d",&n)){
if(n==) break;
for(int i=;i<=n;i++){
scanf("%d",&kk[i].len);
kk[i].l=;
for(int j=;j<i;j++){
kk[i].l=max(kk[i].l,kk[j].r-abs(kk[i].len-kk[j].len));
}
kk[i].r=kk[i].l+*kk[i].len;
}
for(int i=;i<=n;i++){
for(int j=;j<i;j++){
if(kk[i].l<kk[j].r && kk[i].len<kk[j].len)
kk[i].l=kk[j].r;
}
for(int j=i+;j<=n;j++){
if(kk[i].r>kk[j].l && kk[i].len<kk[j].len)
kk[i].r=kk[j].l;
}
}
int flag=;
for(int i=;i<=n;i++){
if(kk[i].l<kk[i].r){
if(flag) flag=;
else printf(" ");
printf("%d",i);
}
}
printf("\n");
}
return ;
}

 

POJ 3347 Kadj Squares (计算几何)的更多相关文章

  1. POJ 3347 Kadj Squares 计算几何

    求出正方形的左右端点,再判断是否覆盖 #include <iostream> #include <cstdio> #include <cstring> #inclu ...

  2. POJ 3347 Kadj Squares

    Kadj Squares Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2132   Accepted: 843 Descr ...

  3. POJ 3347 Kadj Squares (计算几何+线段相交)

    题意:从左至右给你n个正方形的边长,接着这些正方形都按照旋转45度以一角为底放置坐标轴上,最左边的正方形左端点抵住y轴,后面的正方形依次紧贴前面所有正方形放置,问从上方向下看去,有哪些正方形是可以被看 ...

  4. 简单几何(线段覆盖) POJ 3347 Kadj Squares

    题目传送门 题意:告诉每个矩形的边长,它们是紧贴着的,问从上往下看,有几个还能看到. 分析:用网上猥琐的方法,将边长看成左端点到中心的距离,这样可以避免精度问题.然后先求出每个矩形的左右端点,然后如果 ...

  5. POJ 3347 Kadj Squares (线段覆盖)

    题目大意:给你几个正方形的边长,正方一个顶点在x轴上然后边与x轴的夹角为45度,每个正方形都是紧贴的,问从上面看能看的正方形的编号 题目思路:线段覆盖,边长乘上2防止产生小数,求出每个正方形与x轴平行 ...

  6. [poj] 3347 Kadj Square || 计算几何的“线段覆盖”

    原题 多组数据,给出n个正方形的边长,使他们以45度角倾斜的情况下最靠左(在第一象限内),如图.求从上看能看到哪几个完整的正方形. 借鉴于https://www.cnblogs.com/Ritchie ...

  7. poj3347 Kadj Squares (计算几何)

    D - Kadj Squares Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Su ...

  8. poj3347 Kadj Squares【计算几何】

    Kadj Squares Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3594   Accepted: 1456 Desc ...

  9. Kadj Squares - POJ 3347

    题目大意:给一些序列的正方形的边长,然后让这个正方形倾斜45度,放在第一象限,一个角要紧挨着x轴,按照输入的顺序放下去,然后问最后从上往下看可以看到那些正方形?   分析:不能算是计算几何题..... ...

随机推荐

  1. 【Git】+安装+使用+配置

    Git安装及使用: https://www.cnblogs.com/ximiaomiao/p/7140456.html Git下载地址: http://git-scm.com/download/win ...

  2. (PAT)L2-012 关于堆的判断 (最小堆)

    题目链接:https://www.patest.cn/contests/gplt/L2-012 将一系列给定数字顺序插入一个初始为空的小顶堆H[].随后判断一系列相关命题是否为真.命题分下列几种: “ ...

  3. PS绘制飘逸彩色丝带教程

    一.新建一个大小适当的图像,点击工具栏上的钢笔工具,使用形状图层来绘制出下图的形状. 二.把形状所在层的填充设为0%,填充设成0是不会影响到图层的,不像不透明度那样会影响图层样式的效果. 三.双击丝带 ...

  4. Redhat6.4安装Oracle 11gr2 64位 注意事项

    安装步骤略, 安装步骤参考:https://www.cnblogs.com/jhlong/p/5442459.html 注意的是,会出现找不到一些依赖库,我根据光盘已有的库安装了所有64位的依赖库,强 ...

  5. hMailServer配置图文详细教程

    https://www.hmailserver.org/viewtopic.php?f=4&t=6

  6. uni-app 引入ecart

    https://blog.csdn.net/CherryLee_1210/article/details/83016706(copy) 1.首先在uni-app中不支持包下载所以得自己先新建一个项目, ...

  7. vue.js实战——方法设置默认参数

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Linux(Ubuntu)使用日记(七)------终端控制器Terminator安装使用

    1.目的 实现分屏效果,如图: 如果使用系统自带的终端,可能会使这种效果: 综上所述,知道我们为什么要安装Terminator了吧. 2.安装过程 Terminator 的安装非常方便,在 Ubunt ...

  9. Centos7 配置和链接FTP

    1:安装vsftpd组建:  yum -y install vsftpd  安装完成以后在目录/etc/vsftpd/vsftpd.conf文件是vsftp的配置文件 2:添加一个专门用来登陆vsft ...

  10. Swift 之Carthage

    1. 安装 $ brew update               //更新brew $ brew install carthage   //下载carthage $ carthage version ...