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轴,按照输入的顺序放下去,然后问最后从上往下看可以看到那些正方形? 分析:不能算是计算几何题..... ...
随机推荐
- Android App接入微信开放平台注意事项
一.Android第三方应用接入微信开放平台的注意事项: 1. 到微信开放平台官网申请正式的AppID(需通过审核),要填写包名.app签名的md5值.至于如何获取app签名信息,官方提供签名包apk ...
- 图片缓存之内存缓存技术LruCache,软引用
每当碰到一些大图片的时候,我们如果不对图片进行处理就会报OOM异常, 这个问题曾经让我觉得很烦恼,后来终于得到了解决, 那么现在就让我和大家一起分享一下吧. 这篇博文要讲的图片缓存机制,我接触到的有两 ...
- POJ 3692 Kindergarten (补图是二分图的最大团问题)
题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...
- UVa725 - Division
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; int ...
- Oracle buffer cache与相关的latch等待事件
buffer cache与相关的latch等待事件 1.buffer cache 2.latch:cache buffers lru chain 3.latch:cache buffers chain ...
- Android堆栈分析
在开发中,与界面跳转联系比较紧密的概念是Task(任务)和Back Stack(回退栈).activity的启动模式会影响Task和Back Stack的状态, 进而影响用户体验.除了启动模式之外,I ...
- Android fragment源码全解析
Fragment 相信基本上每个android developer都用过,但是知晓其原理 用的好的还是不多,今天就从源码的角度上来带着大家分析一下Fragment的源码,对fragment有了更深层次 ...
- 基数排序/Go实现
package main import ( "fmt" ) type Radix struct { length int //序列中最大数的位数 radix [][]int //0 ...
- web-ylbtech-数据库备份-数据库设计
ylbtech-DatabaseDesgin:web-ylbtech-数据库备份-数据库设计 DatabaseName:ylbtech Model:备份 Type:数据库备份设计 Url: 1.A,数 ...
- PyPI镜像网站
镜像列表:http://www.pypi-mirrors.org/ 清华镜像:http://e.pypi.python.org/