D - Kadj Squares

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status

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, andS4 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 nintegers 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

题意:变长不同的n个正方形,斜45度按顺序平放在坐标轴上,尽量靠左但不能跃出x=0,

   问从上往下看,哪些正方形是可见的。

题解:1、假如前i-1个正方形位置都确定了,那么可以让第i个正方形与前i-1个正方形每个

   都计算一次它如果和它相依靠的话左边坐标的值,然后取一个最大的便是这个正方形

   的左端点位置。

   2、对于j<i的正方形,如果i的边长大于j那么j的最右能看到的部分就不会比i的最左端

   点大,反之,i的最左能看到的部分就不会比j最右端点小。

   3、通过第2步筛选,将那些最左能看到的端点比最右能看到端点大或等于的去掉,剩

   下的就是所要求的。

注意:为避免浮点数运算,根号2约掉了,代码中的边长实际上指的就是边长/根号2,也可以

   将该题理解为将正方形投影到x轴上。

#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
struct sa
{
int l,r,len;
}data[];
int main()
{
int n;
while(cin>>n&&n)
{
memset(data,,sizeof(data));
for(int i=;i<n;i++)
{
cin>>data[i].len;
//现在把图形扩大根号2倍
//边长现在是根号2*len 而len现在指的是对角线的一半的长度
for(int j=;j<i;j++)
//当l是最大值的时候,abs那段是两个图形的重叠部分
//每一个data[j].r求的都是假设ij有重合部分的情况的l
//但是只有真正重合的j能求出真正的l也就是最大的l
//根据等腰三角形性质画一画就明白怎么推的了
//等腰三角形指的是以x周为斜边的那个 两个45度
data[i].l=max(data[i].l,data[j].r-abs(data[i].len-data[j].len));
data[i].r=data[i].l+*data[i].len;
}
for(int i=;i<n;i++)
{
for(int j=;j<i;j++)
{
if(data[j].r>data[i].l)//可更新 有两种情况
{
if(data[j].len<data[i].len) //右面大
data[j].r=data[i].l;//右面的把左面的挡住了一块
else
data[i].l=data[j].r;//左面的把右面的挡住了一块
}
}
}
bool first=true;
for(int i=;i<n;i++)
{
if(data[i].l<data[i].r)
{
if(first)
{
cout<<i+;
first=false;
}
else
cout<<" "<<i+;
}
}
cout<<endl;
}
return ;
}

poj3347 Kadj Squares (计算几何)的更多相关文章

  1. poj3347 Kadj Squares【计算几何】

    Kadj Squares Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3594   Accepted: 1456 Desc ...

  2. POJ3347 Kadj Squares

    嘟嘟嘟 题意:给出一堆正方形的边长,且这些正方形都是\(45 ^ {\circ}\)斜放着并且紧挨着的,求从上往下看能看到几个正方形. 真是一道好题--跟计算几何关系不大. 想一下,如果我们能求出正方 ...

  3. POJ 3347 Kadj Squares 计算几何

    求出正方形的左右端点,再判断是否覆盖 #include <iostream> #include <cstdio> #include <cstring> #inclu ...

  4. POJ 3347 Kadj Squares

    Kadj Squares Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2132   Accepted: 843 Descr ...

  5. POJ 3347 Kadj Squares (计算几何)

    题目: Description In this problem, you are given a sequence S1, S2, ..., Sn of squares of different si ...

  6. POJ 3347 Kadj Squares (计算几何+线段相交)

    题意:从左至右给你n个正方形的边长,接着这些正方形都按照旋转45度以一角为底放置坐标轴上,最左边的正方形左端点抵住y轴,后面的正方形依次紧贴前面所有正方形放置,问从上方向下看去,有哪些正方形是可以被看 ...

  7. POJ3347:Kadj Squares——题解

    http://poj.org/problem?id=3347 题目大意:给定一些正方形的边长,让他们尽可能向左以45°角排列(不能互相重合),求在上面看只能看到哪几个正方形. ———————————— ...

  8. Kadj Squares - POJ 3347

    题目大意:给一些序列的正方形的边长,然后让这个正方形倾斜45度,放在第一象限,一个角要紧挨着x轴,按照输入的顺序放下去,然后问最后从上往下看可以看到那些正方形?   分析:不能算是计算几何题..... ...

  9. 简单几何(线段覆盖) POJ 3347 Kadj Squares

    题目传送门 题意:告诉每个矩形的边长,它们是紧贴着的,问从上往下看,有几个还能看到. 分析:用网上猥琐的方法,将边长看成左端点到中心的距离,这样可以避免精度问题.然后先求出每个矩形的左右端点,然后如果 ...

随机推荐

  1. (转)老生常谈-从输入url到页面展示到底发生了什么

    刚开始写这篇文章还是挺纠结的,因为网上搜索"从输入url到页面展示到底发生了什么",你可以搜到一大堆的资料.而且面试这道题基本是必考题,二月份面试的时候,虽然知道这个过程发生了什么 ...

  2. Educational Codeforces Round 47 (Rated for Div. 2) :E. Intercity Travelling

    题目链接:http://codeforces.com/contest/1009/problem/E 解题心得: 一个比较简单的组合数学,还需要找一些规律,自己把方向想得差不多了但是硬是找不到规律,还是 ...

  3. Scala Tuple

    Python中的Tuple 元组将多样的对象集合到一起,元素不能修改,通过索引进行查找, 使用括号"()" 允许重复 Scala中的Tuple 概念跟Python是完全相同的 定义 ...

  4. 介绍PHP的自动加载

    昨天面试被问到了 PHP 的自动加载机制,因为很多概念模糊啦,没回答好,今天特意来总结一下. include 和 require 是PHP中引入文件的两个基本方法,但是每个脚本的开头,都需要包含(in ...

  5. 【转】Django添加静态文件设置

    STATIC_URL = '/statics/'STATIC_ROOT= os.path.join(BASE_DIR, 'statics')STATICFILES_DIRS = ( os.path.j ...

  6. 【转】Ubuntu 14.04下Django+MySQL安装部署全过程

    一.简要步骤.(阿里云Ubuntu14.04) Python安装 Django Mysql的安装与配置 记录一下我的部署过程,也方便一些有需要的童鞋,大神勿喷~ 二.Python的安装 由于博主使用的 ...

  7. Plsql developer 怎么在打开时登陆配置oracel client?

    配置前 logon 这块是空白的,该怎么配置呢? 看下面 --> 安装完plsql 后 需要安装 oracle client, 这里不再赘述,请自行百度.下面将贴出如何使用 oracle cli ...

  8. 不同编译器下,定义一个地址按x字节对齐的数组

    以前一直用MDK,用__align(4)就可以定义一个首地址被4整除.地址按4字节对齐的数组,但今天用IAR发现这么写编译报错. 搜了一下才发现,原来不同的编译器,需要用不同的表达方式: #if de ...

  9. 雷哥带你走进Javascript

    javascript复习笔记--------------------------------------------1.概念2.面向对象思想3.作用认识4.引入方式5.执行顺序 变量 1)声明方式 x ...

  10. js复制粘贴事件

    一.相应的事件 copy: 在发生复制操作时触发. beforecut: 在发生剪切操作 前 触发. cut: 在 发生 剪切 操作 时 触发. beforepaste: 在 发生 粘贴 操作 前 触 ...