题目:

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. Spring Security(三十一):9.6 Localization(本地化)

    Spring Security supports localization of exception messages that end users are likely to see. If you ...

  2. 环境配置 mac安装bazel

    brew cask install homebrew/cask-versions/java8 brew install bazel

  3. Java面试准备之数据库

    一.考察点 1.联结 1.1 联结的概念: 简单的说,联结是一种机制,用来在一条SELECT语句中关联表,因此称之为联结. 1.2 联结的分类 注意:联结并不代表只有使用join关键字的才算是联结,w ...

  4. AttributeError: Got AttributeError when attempting to get a value for field `password2` on serializer ` UserSerializer`...

    Error_msg: AttributeError: Got AttributeError when attempting to get a value for field `password2` o ...

  5. Golang常见误区(一)

    1.左大括号一般不能单独一行 在其他大多数语言中,{ 的位置你自行决定.Go 比较特别,遵守分号注入规则(automatic semicolon injection):编译器会在每行代码尾部特定分隔符 ...

  6. PS调出清新风格社区街拍照片

    原图: 首先呢,我们还是先看一下在直方图,但是呢,你会发现,这张照片的直方图毫无特色. 简直是标准得不能再标准的直方图了.所以各位那我们就跳过这步吧.你要真跳过这步你就完了.直方图还有三个儿子啊,通道 ...

  7. Jmeter Thread Group中如果存在HTTP request执行失败,就对整个Thread Group重新执行,限定最大执行次数N次

    由于在对WEB系统进行自动化测试的过程中,经常会由于握手连接断开等原因导致HTTP请求发送失败,如果重新执行一次,会是成功的.在每天的自动化冒烟测试过程中,生成在测试报告存在误报,严重浪费了测试人员确 ...

  8. Go 连接 mysql 数据库的简单测试.

    1. import 的时候 总是很慢 容易失败 所以 优先导入几个必须要的包 go get github.com/go-sql-driver/mysql 安装完之后 会在gopath 目录下发现相关的 ...

  9. 下载图片没有关闭http输入流导致下载超时

    在某次接入第三方厂商数据时,需要根据对方提供的URL地址下载图片,当数据量大时会遇到很多的下载图片超时问题,开始以为是第三方厂商的问题,对方排查了很久之后,说是我这边下载数据全部留在缓存区,导致缓存区 ...

  10. 川普和习G-20会面为缓和中美贸易战提供了很大的机会

    川普和习将于这周在Buenos Aires(阿根廷首都)会面,互相商讨虚弱经济全球化的最大威胁. 自从川普在今年七月第一次开始提高中国商品关税之后,对全球的投资者和逐渐削弱的经济活动来说,两位领导人可 ...