POJ 3347 Kadj Squares (计算几何)
题目:
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
题意:依次给出n个正方形的边长 每个正方形在x轴上呈45°摆放并且尽可能放的紧凑 问从上方看时能看见哪些正方形
思路:对于第i个正方形 判断前i-1个正方形如果和它相交的话左端点的位置 最后取一个最大值作为整个正方形的左端点位置
对于j<i的正方形 如果i的边长大于j 那么j的最右能看到的部分就不会比i的最左端点大 反之 i的最左能看到的部分就不会比j最右端点小
再将最左能看到的端点比最右能看到的端点去掉
为了避免浮点数 将每条边乘上sqrt(2)然后约掉 效果等于将正方形投影到x轴上
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n; struct node{
int l,r,len;
}kk[maxn]; int main(){
while(~scanf("%d",&n)){
if(n==) break;
for(int i=;i<=n;i++){
scanf("%d",&kk[i].len);
kk[i].l=;
for(int j=;j<i;j++){
kk[i].l=max(kk[i].l,kk[j].r-abs(kk[i].len-kk[j].len));
}
kk[i].r=kk[i].l+*kk[i].len;
}
for(int i=;i<=n;i++){
for(int j=;j<i;j++){
if(kk[i].l<kk[j].r && kk[i].len<kk[j].len)
kk[i].l=kk[j].r;
}
for(int j=i+;j<=n;j++){
if(kk[i].r>kk[j].l && kk[i].len<kk[j].len)
kk[i].r=kk[j].l;
}
}
int flag=;
for(int i=;i<=n;i++){
if(kk[i].l<kk[i].r){
if(flag) flag=;
else printf(" ");
printf("%d",i);
}
}
printf("\n");
}
return ;
}
POJ 3347 Kadj Squares (计算几何)的更多相关文章
- POJ 3347 Kadj Squares 计算几何
求出正方形的左右端点,再判断是否覆盖 #include <iostream> #include <cstdio> #include <cstring> #inclu ...
- POJ 3347 Kadj Squares
Kadj Squares Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2132 Accepted: 843 Descr ...
- POJ 3347 Kadj Squares (计算几何+线段相交)
题意:从左至右给你n个正方形的边长,接着这些正方形都按照旋转45度以一角为底放置坐标轴上,最左边的正方形左端点抵住y轴,后面的正方形依次紧贴前面所有正方形放置,问从上方向下看去,有哪些正方形是可以被看 ...
- 简单几何(线段覆盖) POJ 3347 Kadj Squares
题目传送门 题意:告诉每个矩形的边长,它们是紧贴着的,问从上往下看,有几个还能看到. 分析:用网上猥琐的方法,将边长看成左端点到中心的距离,这样可以避免精度问题.然后先求出每个矩形的左右端点,然后如果 ...
- POJ 3347 Kadj Squares (线段覆盖)
题目大意:给你几个正方形的边长,正方一个顶点在x轴上然后边与x轴的夹角为45度,每个正方形都是紧贴的,问从上面看能看的正方形的编号 题目思路:线段覆盖,边长乘上2防止产生小数,求出每个正方形与x轴平行 ...
- [poj] 3347 Kadj Square || 计算几何的“线段覆盖”
原题 多组数据,给出n个正方形的边长,使他们以45度角倾斜的情况下最靠左(在第一象限内),如图.求从上看能看到哪几个完整的正方形. 借鉴于https://www.cnblogs.com/Ritchie ...
- poj3347 Kadj Squares (计算几何)
D - Kadj Squares Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
- poj3347 Kadj Squares【计算几何】
Kadj Squares Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3594 Accepted: 1456 Desc ...
- Kadj Squares - POJ 3347
题目大意:给一些序列的正方形的边长,然后让这个正方形倾斜45度,放在第一象限,一个角要紧挨着x轴,按照输入的顺序放下去,然后问最后从上往下看可以看到那些正方形? 分析:不能算是计算几何题..... ...
随机推荐
- 【Windows】+ win10 通过KMS激活
win10激活到期 通过KMS再次激活(亲测有效):http://www.xitongcheng.com/jiaocheng/win10_article_44435.html
- Linux内存管理 (12)反向映射RMAP
专题:Linux内存管理专题 关键词:RMAP.VMA.AV.AVC. 所谓反向映射是相对于从虚拟地址到物理地址的映射,反向映射是从物理页面到虚拟地址空间VMA的反向映射. RMAP能否实现的基础是通 ...
- 静态代理与JDK动态代理
demo地址: https://github.com/ZbLeaning/leaning 代理: 为其他对象提供一种代理以控制对这个对象的访问.分为静态代理和动态代理.代理模式的目的就是为真实业务对象 ...
- OSGI target环境配置过程
新建一个通用工程 新建target环境 新建存放依赖包的目录 新建server目录,用于存放server.target对应的依赖包. 在server目录下,新建plugins目录 新建目录之后的, ...
- Python Revisited Day 07 (文件处理)
目录 7.1 二进制数据的读与写 7.1.1 带可选压缩的Pickle 7.1.2 带可选压缩的原始二进制数据 7.2 文本文件的写入与分析 7.2.1 写入文本 7.2.2 分析文本 7.2.3 使 ...
- pyspider爬虫框架webui简介-爬取阿里招聘信息
命令行输入pyspider开启pyspider 浏览器打开http://localhost:5000/ group表示组名,几个项目可以同一个组名,方便管理,当组名修改为delete时,项目会在一天后 ...
- MyBatis 传List参数 nested exception is org.apache.ibatis.binding.BindingException: Parameter 'idList' not found.
在MyBatis传入List参数时,MyBatis报错:nested exception is org.apache.ibatis.binding.BindingException: Paramete ...
- 只能用Android studio做平台移植了! 在Windows10下, 开发Android。
安装好IDE后, 会一直显示同步失败, 看看如下步骤: 需要注意的是: -> 安装NDK 自带的NDK版本有问题 自己去下一个15版本的 -> 按照系统提示一步一步安装其他 ...
- 利用Python中SocketServer 实现客户端与服务器间非阻塞通信
利用SocketServer模块来实现网络客户端与服务器并发连接非阻塞通信 版权声明 本文转自:http://blog.csdn.net/cnmilan/article/details/9664823 ...
- Vuex、axios、跨域请求处理和import/export的注意问题
一.Vuex 1.介绍 vuex是一个专门为Vue.js设计的集中式状态管理架构. 对于状态,我们把它理解为在data中需要共享给其他组件使用的部分数据. Vuex和单纯的全局对象有以下不同: 1. ...