poj 3347 Kadj Squares(线段切割)
来源:互联网 发布:最大公约数怎么求算法 编辑:程序博客网 时间:2024/05/01 05:09
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
43 5 1 432 1 20
Sample Output
1 2 41 3
Source
#include<cmath>#include<cstdio>#include<iostream>#include<algorithm>using namespace std;const int mm=55;struct seg{ int id,l,r;}g[mm];int a[mm],b[mm];int i,j,n;bool cmp(seg u,seg v){ return a[u.id]<a[v.id];}bool ok(int i,int l,int r){ if(i>=n)return 1; if(r<=g[i].l||l>=g[i].r) { if(ok(i+1,l,r))return 1; } else if(l<g[i].l) { if(ok(i+1,l,g[i].l))return 1; } else if(r>g[i].r) { if(ok(i+1,g[i].r,r))return 1; } return 0;}int main(){ while(scanf("%d",&n),n) { for(i=0;i<n;++i) { scanf("%d",&a[i]); b[i]=a[i]*2; for(j=0;j<i;++j) if(a[i]>=a[j])b[i]=max(b[i],b[j]+a[j]*4); else b[i]=max(b[i],b[j]+a[i]*4); g[i].id=i; g[i].l=b[i]-a[i]*2; g[i].r=b[i]+a[i]*2; } sort(g,g+n,cmp); for(j=i=0;i<n;++i) if(ok(i+1,g[i].l,g[i].r)) a[j++]=g[i].id+1; sort(a,a+j); for(i=0;i<j;++i) printf("%d%c",a[i],i<j-1?' ':'\n'); } return 0;}
- poj 3347 Kadj Squares(线段切割)
- POJ 3347 Kadj Squares
- poj 3347 Kadj Squares
- poj 3347 Kadj Squares
- POJ 3347 Kadj Squares
- POJ 3347 Kadj Squares (几何+线段树)
- POJ 3347 Kadj Squares(复杂的线段相交问题)
- POJ 3347 Kadj Squares(技巧)
- Kadj Squares - POJ 3347 几何
- POJ 3347 Kadj Squares <几何>
- POJ 3347 HDU 2417 Kadj Squares
- poj 3347 Kadj Squares(计算几何)
- poj 3347 Kadj Squares(计算几何)
- POJ 3347 Kadj Squares(计算几何)
- POJ 3347 && HDU 2417 Kadj Squares(计算几何)
- Kadj Squares(poj3347线段的区间覆盖)
- poj 3347 Kadj Squares(扩大数据运算的典型应用+映射)
- poj 3347 Kadj Squares(扩大数据运算的典型应用+映射)
- Reverse_tcp反向连接获得shell实验
- 设计模式之装饰模式
- java中的几种对象引用(Reference)
- IOS设计中的黄金分割
- linux查看内存free
- poj 3347 Kadj Squares(线段切割)
- 选择排序算法
- 20120809-课堂笔记--复合
- 网页设计命名规范
- Android ApiDemo学习(二)notification——3 NotifyWithText——Toast(提示)
- boost提供的智能指针
- linux查看内存top
- 黄金分割的金苹果——apple设计中的黄金分割
- 设计模式---适配器模式