TJU 4072 3D Birds-Shooting Game
4072. 3D Birds-Shooting Game
Time Limit: 3.0 Seconds Memory Limit: 65536K Total Runs: 167 Accepted Runs: 37
There are N birds in a 3D space, let x, y and z denote their coordinates in each dimension. You, the excellent shooter, this time sit in a helicopter and want to shoot these birds with your gun. Through the window of the helicopter you can only see a rectangle area and you choose to shoot the highest bird in view (the helicopter is above all the birds and the rectangle area is parallel to the ground). Now given the rectangle area of your view, can you figure out which bird to shoot?
Input
First line will be a positive integer T (1≤T≤10) indicating the test case number.. Following there are T test cases.. Each test case begins with a positive integer N (1≤N≤10000), the number of birds.. Then following N lines with three positive integers x, y and z (1≤x,y,z≤100000), which are the coordinates of each bird (you can assume no two birds have the same height z).. Next will be a positive integer Q (1≤Q≤10000) representing the number of query.. Following Q lines with four positive integers which are the lower-left and upper-right points' coordinates of the rectangle view area.. (please note that after each query you will shoot down the bird you choose and you can't shoot it any more in the later).
Output
For each query output the coordinate of the bird you choose to shoot or output 'Where are the birds?' (without the quotes) if there are no birds in your view.
Sample Input
2
3
1 1 1
2 2 2
3 3 3
2
1 1 2 2
1 1 3 3
2
1 1 1
3 3 3
2
2 2 3 3
2 2 3 3
Sample Output
2 2 2
3 3 3
3 3 3
Where are the birds?
Source: TJU Team Selection 2014 Round1
题意:三维空间中有N个点,给出其坐标;接下来Q个询问,每次询问给出一个垂直于z轴的矩形,矩形边界与坐标轴平行,求出此矩形范围内z坐标最大的点,输出其坐标,如果没有满足条件的点,输出"Where are the birds?"。每个点只能被输出一次。(所有点的z坐标值都不相同)
分析:典型的k-d树,在三维空间中查询满足条件的解。建树的时候,依次按照x,y,z来划分空间(也可以优化)。查询的时候,如果遇到以z坐标划分空间的情况,则先查询上部空间,查询下层空间的时候,先比较当前找到的答案与划分点的z坐标值,如果当前答案比该值还大,则没有再必要查询下层空间。
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 10005 int idx;
struct point{
int x[];
bool operator < (const point &a) const{
return x[idx] < a.x[idx];
}
}; point p[N];
point tr[N<<];
int cnt[N<<];
bool flag[N<<]; int x1, x2, y1, y2;
void build(int l, int r, int u, int dep)
{
if(l > r) return;
cnt[u] = r-l+;
if(l == r)
{
tr[u] = p[l];
return;
}
idx = dep%;
int mid = l+r>>;
nth_element(p+l, p+mid, p+r+);
tr[u] = p[mid];
build(l, mid-, u<<, dep+);
build(mid+, r, u<<|, dep+);
} int ans, id;
bool check(point u)
{
return u.x[] >= x1 && u.x[] <= x2 && u.x[] >= y1 && u.x[] <= y2;
}
void query(int u, int dep)
{
if(cnt[u] == ) return;
if(!flag[u] && check(tr[u]))
if(tr[u].x[] > ans) ans = tr[u].x[], id = u;
int tid = dep%;
if(tid == )
{
if(x2 < tr[u].x[]) query(u<<, dep+);
else if(x1 > tr[u].x[]) query(u<<|, dep+);
else {
query(u<<, dep+);
query(u<<|, dep+);
}
}
else if(tid == )
{
if(y2 < tr[u].x[]) query(u<<, dep+);
else if(y1 > tr[u].x[]) query(u<<|, dep+);
else {
query(u<<, dep+);
query(u<<|, dep+);
}
}
else if(tid == )
{
query(u<<|, dep+);
if(ans < tr[u].x[])//这儿因为写成if(ans == -1)错了很多次
query(u<<, dep+);
}
} int main()
{
int T, n, q;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i = ; i < n; i++) scanf("%d %d %d", &p[i].x[], &p[i].x[], &p[i].x[]);
memset(flag, , sizeof(flag));
memset(cnt, , sizeof(cnt));
build(, n-, , ); scanf("%d", &q);
while(q--)
{
ans = -;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
query(, );
if(ans == -)
puts("Where are the birds?");
else{
printf("%d %d %d\n", tr[id].x[], tr[id].x[], tr[id].x[]);
flag[id] = ;
}
}
}
return ;
}
TJU 4072 3D Birds-Shooting Game的更多相关文章
- Hdu4742-Pinball Game 3D(cdq分治+树状数组)
Problem Description RD is a smart boy and excel in pinball game. However, playing common 2D pinball ...
- HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)
Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4742 Pinball Game 3D(三维LIS&cdq分治&BIT维护最值)
Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 【20.00%】【codeforces 44G】Shooting Gallery
time limit per test5 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【16.50%】【CF 44G】Shooting Gallery
time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standa ...
- 2D、3D形变
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; color: #a5b2b9 } span.Apple-tab-span { ...
- CSS3 3D立方体效果-transform也不过如此
CSS3系列已经学习了一段时间了,第一篇文章写了一些css3的奇技淫巧,原文戳这里,还获得了较多网友的支持,在此谢过各位,你们的支持是我写文章最大的动力^_^. 那么这一篇文章呢,主要是通过一个3D立 ...
- 三分钟学会用 js + css3 打造酷炫3D相册
之前发过该文,后来不知怎么回事不见了,现在重新发一下. 中秋主题的3D旋转相册 如图,这是通过Javascript和css3来实现的.整个案例只有不到80行代码,我希望通过这个案例,让正处于迷茫期的j ...
- 使用CSS3实现一个3D相册
CSS3系列我已经写过两篇文章,感兴趣的同学可以先看一下CSS3初体验之奇技淫巧,CSS3 3D立方体效果-transform也不过如此 第一篇主要列出了一些常用或经典的CSS3技巧和方法:第二篇是一 ...
随机推荐
- [CSP-S模拟测试]:不等式(数学)
题目描述 小$z$热衷于数学.今天数学课的内容是解不等式:$L\leqslant S\times x\leqslant R$.小$z$心想这也太简单了,不禁陷入了深深的思考:假如已知$L,R,S,M$ ...
- vue2.X 与 vue1.X 的区别
vue2.0: bower info vue http://vuejs.org/ 到了2.0以后,有哪些变化? 1. 在每个组件模板,不在支持片段代码 组件中模板: 之前: <template& ...
- 【CDN+】 Hbase入门 以及Hbase shell基础命令
前言 大数据的基础离不开Hbase, 本文就hbase的基础概念,特点,以及框架进行简介, 实际操作种需要注意hbase shell的使用. Hbase 基础 官网:https://hbase.ap ...
- day32—CSS多列布局学习
转行学开发,代码100天——2018-04-17 关于多列布局,前期已经梳理过,今天的培训课程学习中再次提及,趁此也做个总结和检验. 多列布局的介绍参考: day08—css布局解决方案之多列布局 ...
- HttpSessionBindingListener和HttpSessionAttributeListener区别
HttpSessionBindingListener和HttpSessionAttributeListener是两个经常让初学者弄混的监听器,其实它们有很大的区别.这2个监听器在文章中简称为Bindi ...
- python实现读取excel
实现代码如下: #读取excel,将每行数据放入一个列表,将所有列表放入一个列表形成二维列表,返回该二维列表 import xlrd class ReadExcel: def read_excel(s ...
- MapReduce(3): Partitioner, Combiner and Shuffling
Partitioner: Partitioning and Combining take place between Map and Reduce phases. It is to club the ...
- "CoolShell puzzle game" writeup
地址:http://fun.coolshell.cn/ Fuck your brain 看到一大串符号,还以为是 js 代码,结果放到 Chrome 控制台执行没有任何结果,然后搜了一下发现有一门叫B ...
- Self-Attention 和 Transformer
1.Self-Attention 之前的RNN输入是难以并行化的,我们下一个输入可能依赖前一个输出,只有知道了前面的输出才能计算后面的输出. 于是提出了 self-attention ,但是这时候 $ ...
- Day5---Python的random库
random库 1.random库是随机数的Python标准库 2.原理 : random生成的伪随机数,而采用梅森旋转算法生成的(伪)随机序列中的元素叫做伪随机数 https://liam.pa ...