博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3347 Kadj Squares
阅读量:5790 次
发布时间:2019-06-18

本文共 2700 字,大约阅读时间需要 9 分钟。

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

43 5 1 432 1 20

Sample Output

1 2 41 3

Source

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

 

 
 
 

转载地址:http://tagyx.baihongyu.com/

你可能感兴趣的文章
Web框架的常用架构模式(JavaScript语言)
查看>>
如何用UPA优化性能?先读懂这份报告!
查看>>
这些Java面试题必须会-----鲁迅
查看>>
Linux 常用命令
查看>>
CSS盒模型
查看>>
ng2路由延时加载模块
查看>>
使用GitHub的十个最佳实践
查看>>
脱离“体验”和“安全”谈盈利的游戏运营 都是耍流氓
查看>>
慎用!BLEU评价NLP文本输出质量存在严重问题
查看>>
JAVA的优势就是劣势啊!
查看>>
ELK实战之logstash部署及基本语法
查看>>
帧中继环境下ospf的使用(点到点模式)
查看>>
BeanShell变量和方法的作用域
查看>>
LINUX下防恶意扫描软件PortSentry
查看>>
由数据库对sql的执行说JDBC的Statement和PreparedStatement
查看>>
springmvc+swagger2
查看>>
我的友情链接
查看>>
Java Web Application 自架构 一 注解化配置
查看>>
如何 debug Proxy.pac文件
查看>>
Python 学习笔记 - 面向对象(特殊成员)
查看>>