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轴,按照输入的顺序放下去,然后问最后从上往下看可以看到那些正方形? 分析:不能算是计算几何题..... ...
随机推荐
- P1744 采购特价商品 题解(讲解图论)
图论的超级初级题目(模板题) 最短路径的模板题 图是啥?(白纸上的符号?) 对于一个拥有n个顶点的无向连通图,它的边数一定多于n-1条.若从中选择n-1条边,使得无向图仍然连通,则由n个顶点及这 n- ...
- Java连接数据库,及增删改查
自定义连接数据库的util类 package com.shuzf.jdbc; import java.sql.Connection; import java.sql.DriverManager; im ...
- 【转】localStorage使用总结
原文地址:https://www.cnblogs.com/st-leslie/p/5617130.html 一.什么是localStorage.sessionStorage 在HTML5中,新加入了一 ...
- 领域驱动设计系列文章(2)——浅析VO、DTO、DO、PO的概念、区别和用处
本篇文章主要讨论一下我们经常会用到的一些对象:VO.DTO.DO和PO. 由于不同的项目和开发人员有不同的命名习惯,这里我首先对上述的概念进行一个简单描述,名字只是个标识,我们重点关注其概念: 概念: ...
- Linux利用mysql建立数据库
安装数据库: sudo apt-get install mysql-server 启动服务: sudo service mysql start 连接数据库:sudo mysq ...
- JS 函数节流与防抖
前言 事件的触发权很多时候属于用户,可能会出现下列问题: 向后台发送数据,用户频繁触发,对服务器造成压力: 一些浏览器事件,如window.onresize,window.mousemove等,触发的 ...
- 乐观锁vs悲观锁
引言 为什么需要锁(并发控制) 在并发的环境中,会存在多个用户同时更新同一条数据,这时就会产生冲突. 冲突结果: 丢失更新:一个事务的更新覆盖了其它事务的更新结果,就是所谓的更新丢失. 脏读:当一个事 ...
- Laravel 入口文件解读及生命周期
这里只贴index.php的代码, 深入了解的请访问 https://laravel-china.org/articles/10421/depth-mining-of-laravel-life- ...
- Git各个状态之间转换指令总结
基本状态标识 A- = untracked 未跟踪 A = tracked 已跟踪未修改 A+ = modified - 已修改未暂存 B = staged - 已暂存未提交 C = committe ...
- Sumdiv POJ 1845
http://poj.org/problem?id=1845 题目 Time Limit: 1000MS Memory Limit: 30000K Description Consider two ...