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

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

Source

 
 
 
 
 
这题是在做计算几何的时候遇到的。
 
但是发现有简单的做法,不需要用计算几何。
 
为了避免浮点数运算,把长度乘以sqrt(2).
 
具体看代码吧,代码看得很清楚了。
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std; const int MAXN = ;
struct Node
{
int l,r,len;
};
Node node[MAXN];
int main()
{
int n;
while(scanf("%d",&n) == && n)
{
for(int i = ;i <= n;i++)
{
scanf("%d",&node[i].len);
node[i].l = ;
for(int j = ;j < i;j++)
node[i].l = max(node[i].l,node[j].r - abs(node[i].len - node[j].len));
node[i].r = node[i].l + *node[i].len;
}
for(int i = ;i <= n;i++)
{
for(int j = ;j < i;j++)
if(node[i].l < node[j].r && node[i].len < node[j].len)
node[i].l = node[j].r;
for(int j = i+;j <= n;j++)
if(node[i].r > node[j].l && node[i].len < node[j].len)
node[i].r = node[j].l;
}
bool first = true;
for(int i = ;i <= n;i++)
if(node[i].l < node[i].r)
{
if(first)first = false;
else printf(" ");
printf("%d",i);
}
printf("\n");
}
return ;
}
 
 
 

POJ 3347 Kadj Squares的更多相关文章

  1. POJ 3347 Kadj Squares (计算几何)

    题目: Description In this problem, you are given a sequence S1, S2, ..., Sn of squares of different si ...

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

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

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

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

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

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

  5. POJ 3347 Kadj Squares 计算几何

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

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

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

  7. poj3347 Kadj Squares【计算几何】

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

  8. poj3347 Kadj Squares (计算几何)

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

  9. Kadj Squares - POJ 3347

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

随机推荐

  1. Qt之模型/视图(自定义进度条)

    简述 在之前的章节中分享过关于QHeaderView表头排序.添加复选框等内容,相信大家模型/视图.自定义风格有了一定的了解,下面我们来分享一个更常用的内容-自定义进度条. 实现方式: 从QAbstr ...

  2. Java编程思想(11~17)

    [注:此博客旨在从<Java编程思想>这本书的目录结构上来检验自己的Java基础知识,只为笔记之用] 第十一章 持有对象 11.1 泛型和类型安全的容器>eg: List<St ...

  3. XML中对特殊字符的处置

    str = str.replaceAll("‘", "‘"); str = str.replaceAll("’", "‘" ...

  4. UVa 10878 Decode the tape

    题目很简单,代码也很短.第一遍做的时候,我居然二乎乎的把input里面的小框框忽略掉了,所以WA了一次. 每一行代表一个二进制的ASCII码,'o'代表1,空格代表0,中间的小黑点忽略. 我直接把一行 ...

  5. 通知(NSNotification)

    通知 一个完整的通知一般包含3个属性: - (NSString *)name; // 通知的名称 - (id)object; // 通知发布者(是谁要发布通知) - (NSDictionary *)u ...

  6. 【Python】菜鸟的基本课程继续中

    同样的缩进表示这段代码处于同一个层次. 每一个print都自带一个换行. 定义变量一定要在使用函数等之前. abs(-14) ======= 取绝对值函数 内建函数 print abs(-14) == ...

  7. python numpy argsort函数用法

    numpy.argsort numpy.argsort(a, axis=-1, kind='quicksort', order=None)[source] Returns the indices th ...

  8. Android无法调用JS的问题解决

    1.启用JS webView.getSettings().setJavaScriptEnabled(true); 2.需要使用WebChromeClient(如果没有这个Client,很多东西不会响应 ...

  9. 嵌入式 linux下利用backtrace追踪函数调用堆栈以及定位段错误

    嵌入式 linux下利用backtrace追踪函数调用堆栈以及定位段错误 2015-05-27 14:19 184人阅读 评论(0) 收藏 举报  分类: 嵌入式(928)  一般察看函数运行时堆栈的 ...

  10. 自己的一个LESS工具函数库

    自己大概在一年前开始使用LESS编写样式,现在感觉不用LESS都不会写样式了.现在写静态页面完全离不开LESS与Zen Coding,我可以不用什么IDE,但这两个工具却必须要,当然也强烈推荐看到这篇 ...