poj3347 Kadj Squares【计算几何】
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 3594 | Accepted: 1456 |
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
Source
题意:
n个正方形45度角的放,边靠着边,放完了之后从顶部往下看。有哪些正方形没有被挡住。
思路:
我们从这张图来看,正方形之间的三角形是等腰三角形,边长是两个正方形边长的较小值。
我们现在记下每个正方形的最左的横坐标,和最右的横坐标,和边长。并且我们假设输入的边长是实际边长投影在横坐标上的长度。
因为大家都同时放大,是不影响结果的。
当我们摆好了前面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 ;
}
poj3347 Kadj Squares【计算几何】的更多相关文章
- poj3347 Kadj Squares (计算几何)
D - Kadj Squares Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
- POJ3347 Kadj Squares
嘟嘟嘟 题意:给出一堆正方形的边长,且这些正方形都是\(45 ^ {\circ}\)斜放着并且紧挨着的,求从上往下看能看到几个正方形. 真是一道好题--跟计算几何关系不大. 想一下,如果我们能求出正方 ...
- 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 (计算几何)
题目: Description In this problem, you are given a sequence S1, S2, ..., Sn of squares of different si ...
- POJ 3347 Kadj Squares (计算几何+线段相交)
题意:从左至右给你n个正方形的边长,接着这些正方形都按照旋转45度以一角为底放置坐标轴上,最左边的正方形左端点抵住y轴,后面的正方形依次紧贴前面所有正方形放置,问从上方向下看去,有哪些正方形是可以被看 ...
- POJ3347:Kadj Squares——题解
http://poj.org/problem?id=3347 题目大意:给定一些正方形的边长,让他们尽可能向左以45°角排列(不能互相重合),求在上面看只能看到哪几个正方形. ———————————— ...
- Kadj Squares - POJ 3347
题目大意:给一些序列的正方形的边长,然后让这个正方形倾斜45度,放在第一象限,一个角要紧挨着x轴,按照输入的顺序放下去,然后问最后从上往下看可以看到那些正方形? 分析:不能算是计算几何题..... ...
- 简单几何(线段覆盖) POJ 3347 Kadj Squares
题目传送门 题意:告诉每个矩形的边长,它们是紧贴着的,问从上往下看,有几个还能看到. 分析:用网上猥琐的方法,将边长看成左端点到中心的距离,这样可以避免精度问题.然后先求出每个矩形的左右端点,然后如果 ...
随机推荐
- WebBrowser中html元素如何触发winform事件
这个问题来自论坛提问,对dom稍微了解的话还是比较简单的,只要注册一下事件就可以了. C#代码如下: using System;using System.ComponentModel;using Sy ...
- GoF--服务定位器模式
服务定位器模式(Service Locator Pattern)用在我们想使用 JNDI 查询定位各种服务的时候.考虑到为某个服务查找 JNDI 的代价很高,服务定位器模式充分利用了缓存技术.在首次请 ...
- Netty权威指南之伪异步I/O编程
为了解决同步阻塞I/O一个链路需要一个线程处理问题,对BIO模型做了优化——后端通过一个线程池处理多个客户端的请求接入,设置线程最大值,防止线程并发接入导致的线程耗尽. 当有新的客户端接入时,将客户端 ...
- Python学习笔记(15)- os\os.path 操作文件
程序1 编写一个程序,统计当前目录下每个文件类型的文件数,程序实现如图: import os def countfile(path): dict1 = {} # 定义一个字典 all_files = ...
- 数据库iops的理解
想购买阿里云的RDS mysql,想请教下最大连接数是请求数吗?如下图,600最大可支持连接数,那一个页面查询30次,20个人同时请求,数据库不就超载了么?(内存2400MB,专用数据服务器,只能支持 ...
- 使用 vux 框架
1)vux官网:https://vux.li/#/ 2)通过 vue-cli 工具使用 vux 1.如果没有安装 nodejs,请先前往 nodejs 官网下载并安装 nodejs,传送门:https ...
- linux系统抓包命令
IP地址抓包:tcpdump -i any host 1.1.1.2 -n 端口抓包: tcpdump -i any port 6789 -n wireshak工具抓包:tcp.port == 678 ...
- linux下命令学习
1 在linux中,./代表当前目录下 例如 创建一个文件夹123 mkdir ./123 ->当前目录下创建一个123文件夹 mkdir -p ./123/456 在当前目录下创建一 ...
- codeforces水题100道 第十七题 Codeforces Beta Round #25 (Div. 2 Only) A. IQ test (brute force)
题目链接:http://www.codeforces.com/problemset/problem/25/A题意:在n个书中找到唯一一个奇偶性和其他n-1个数不同的数.C++代码: #include ...
- LOCAL_WHOLE_STATIC_LIBRARIES与LOCAL_STATIC_LIBRARIES的区别
在分析Jelly Bean Audio Subsystem的时候,发现HAL层的库audio_policy.xxx.so与其依赖的静态库libaudiopolicy_legacy.a都有audio_p ...