POJ 3347 Kadj Squares
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 2132 | Accepted: 843 |
Description
In this problem, you are given a sequence S1, S2, ..., 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 S1, S2, 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
#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的更多相关文章
- POJ 3347 Kadj Squares (计算几何)
题目: Description In this problem, you are given a sequence S1, S2, ..., Sn of squares of different si ...
- POJ 3347 Kadj Squares (计算几何+线段相交)
题意:从左至右给你n个正方形的边长,接着这些正方形都按照旋转45度以一角为底放置坐标轴上,最左边的正方形左端点抵住y轴,后面的正方形依次紧贴前面所有正方形放置,问从上方向下看去,有哪些正方形是可以被看 ...
- 简单几何(线段覆盖) POJ 3347 Kadj Squares
题目传送门 题意:告诉每个矩形的边长,它们是紧贴着的,问从上往下看,有几个还能看到. 分析:用网上猥琐的方法,将边长看成左端点到中心的距离,这样可以避免精度问题.然后先求出每个矩形的左右端点,然后如果 ...
- POJ 3347 Kadj Squares (线段覆盖)
题目大意:给你几个正方形的边长,正方一个顶点在x轴上然后边与x轴的夹角为45度,每个正方形都是紧贴的,问从上面看能看的正方形的编号 题目思路:线段覆盖,边长乘上2防止产生小数,求出每个正方形与x轴平行 ...
- POJ 3347 Kadj Squares 计算几何
求出正方形的左右端点,再判断是否覆盖 #include <iostream> #include <cstdio> #include <cstring> #inclu ...
- [poj] 3347 Kadj Square || 计算几何的“线段覆盖”
原题 多组数据,给出n个正方形的边长,使他们以45度角倾斜的情况下最靠左(在第一象限内),如图.求从上看能看到哪几个完整的正方形. 借鉴于https://www.cnblogs.com/Ritchie ...
- poj3347 Kadj Squares【计算几何】
Kadj Squares Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3594 Accepted: 1456 Desc ...
- poj3347 Kadj Squares (计算几何)
D - Kadj Squares Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
- Kadj Squares - POJ 3347
题目大意:给一些序列的正方形的边长,然后让这个正方形倾斜45度,放在第一象限,一个角要紧挨着x轴,按照输入的顺序放下去,然后问最后从上往下看可以看到那些正方形? 分析:不能算是计算几何题..... ...
随机推荐
- openfire源码分析
启动流程 Socket接口 Socket通信使用Mina框架实现,是XMPP协议的处理入口,具体为: 消息接收后由不同的节处理器处理: StanzaHandler基础消息类型,之后进行消息路由: 最后 ...
- Git server安装和配置
yum install git yum install git-dameon toiseGit
- 解决 border-radius 元素在应用了 transform 的子元素 时overflow:hidden 失效的问题
受大家启迪,于是最近深入研究了一下Css3中的一些属性.之中也是碰到了个不为我知的问题,在这里特此总结并与大家分享. 问题重现:在父元素上应用了 border-radius 的圆角属性.加上 ove ...
- XManager介绍、安装、使用
简介 Xmanager是一款小巧.便捷的浏览远端X窗口系统的工具.在工作中经常使用Xmanager来登录远端的Linux系统,在X窗口系统上作图形化的操作.Xmanager可以将PC变成X Windo ...
- android中handler用法总结
一.Handler的定义: Handler主要接收子线程发送的数据, 并用此数据配合主线程更新UI,用来跟UI主线程交互用.比如可以用handler发送一个message,然后在handler的线程中 ...
- android事件系列-onTouch事件与手势操作
提示记忆:应用流程:在Activity中对控件执行 view.setOnTouchListener( OnTouchListener i);实现里面的OnTouchListener 接口中的方法,重点 ...
- php使用memcache与memcached扩展对key值的影响
php使用php_memcache时,key值为session_id()的值,也就是客户端cookie记录的值. php使用php_memcache时,key值为session_id()的值加上mem ...
- Linux用户(组)管理
在linux中系统中,它并不认识帐号名称.它认识的是我们的帐号ID,帐号ID保存在/etc/passwd文件中.我们在登录linux主机时,在输入完帐号和密码时,linux会先查找/etc/passw ...
- UVa 11520 Fill the Square 填充正方形
在一个 n * n 网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同.如果有多重填法,则要求按照从上到下,从左到右的顺序把所有格子连 ...
- 【转】Bootloader之uBoot简介(转)
原文网址:http://blog.csdn.net/sadamoo/article/details/8139946 来自http://blog.ednchina.com/hhuwxf/1915416/ ...