首页 技术 正文
技术 2022年11月8日
0 收藏 817 点赞 1,843 浏览 2301 个字

Kadj Squares

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 3594   Accepted: 1456

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 xy 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 S1Si-1.

poj3347 Kadj Squares【计算几何】

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

Tehran 2006

题意:

n个正方形45度角的放,边靠着边,放完了之后从顶部往下看。有哪些正方形没有被挡住。

思路:

poj3347 Kadj Squares【计算几何】

我们从这张图来看,正方形之间的三角形是等腰三角形,边长是两个正方形边长的较小值。

我们现在记下每个正方形的最左的横坐标,和最右的横坐标,和边长。并且我们假设输入的边长是实际边长投影在横坐标上的长度。

因为大家都同时放大,是不影响结果的。

当我们摆好了前面i-1个正方形之后,摆第i个正方形。那么可以知道第i个正方形的左端点应该是前面所有正方形的最右端点减去两个正方形边长之差。

摆好第i个正方形之后我们再看,前i-1个正方形中有哪几个被遮掉了一部分。

有两种情况,一种是左边的遮掉右边的,一种是右边的遮掉左边的。

 #include <iostream>
#include <set>
#include <cmath>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define inf 0x7f7f7f7f const int maxn = ;
int n;
struct node{
int len, l, r;
}squ[maxn]; int main()
{
while(scanf("%d", &n) != EOF && n){
for(int i = ; i <= n; i++){
scanf("%d", &squ[i].len);
squ[i].l = ;
for(int j = ; j < i; j++){
squ[i].l = max(squ[i].l, squ[j].r - abs(squ[i].len - squ[j].len));
}
squ[i].r = squ[i].l + * squ[i].len;
for(int j = ; j < i; j++){
if(squ[j].r > squ[i].l){
if(squ[i].len > squ[j].len){
squ[j].r = squ[i].l;
}
else{
squ[i].l = squ[j].r;
}
}
}
} bool flag = true;
for(int i = ; i <= n; i++){
if(squ[i].l < squ[i].r){
if(flag){
printf("%d", i);
flag = false;
}
else{
printf(" %d", i);
}
}
}
printf("\n"); }
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,486
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,126
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,287