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的更多相关文章

  1. Hdu4742-Pinball Game 3D(cdq分治+树状数组)

    Problem Description RD is a smart boy and excel in pinball game. However, playing common 2D pinball ...

  2. HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)

    Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. hdu 4742 Pinball Game 3D(三维LIS&amp;cdq分治&amp;BIT维护最值)

    Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. 【20.00%】【codeforces 44G】Shooting Gallery

    time limit per test5 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【16.50%】【CF 44G】Shooting Gallery

    time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standa ...

  6. 2D、3D形变

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; color: #a5b2b9 } span.Apple-tab-span { ...

  7. CSS3 3D立方体效果-transform也不过如此

    CSS3系列已经学习了一段时间了,第一篇文章写了一些css3的奇技淫巧,原文戳这里,还获得了较多网友的支持,在此谢过各位,你们的支持是我写文章最大的动力^_^. 那么这一篇文章呢,主要是通过一个3D立 ...

  8. 三分钟学会用 js + css3 打造酷炫3D相册

    之前发过该文,后来不知怎么回事不见了,现在重新发一下. 中秋主题的3D旋转相册 如图,这是通过Javascript和css3来实现的.整个案例只有不到80行代码,我希望通过这个案例,让正处于迷茫期的j ...

  9. 使用CSS3实现一个3D相册

    CSS3系列我已经写过两篇文章,感兴趣的同学可以先看一下CSS3初体验之奇技淫巧,CSS3 3D立方体效果-transform也不过如此 第一篇主要列出了一些常用或经典的CSS3技巧和方法:第二篇是一 ...

随机推荐

  1. Android 中的 Matrix

    Matrix 是 Android SDK 提供的一个矩阵类,它代表一个 3 X 3 的矩阵 Matrix主要可以对图像做4种基本变换 Translate 平移变换 Rotate 旋转变换 Scale ...

  2. Android多线程方案

    为主线程减轻负的多线程方案有哪些呢?这些方案分别适合在什么场景下使用? Android系统为我们提供了若干组工具类来帮助解决这个问题. AsyncTask: 为UI线程与工作线程之间进行快速的切换提供 ...

  3. python保存selenium的cookies写入和读出

    def write_cookie(self, cookie): try: with open("cookies%s" % self.uid, "wb+") as ...

  4. vue2.X 与 vue1.X 的区别

    vue2.0: bower info vue http://vuejs.org/ 到了2.0以后,有哪些变化? 1. 在每个组件模板,不在支持片段代码 组件中模板: 之前: <template& ...

  5. 电脑可以识别sd卡手机无法识别 的解决方法。 我成功了。 淘宝买的sd卡 不用退货了。 退的人肝疼

    https://wenku.baidu.com/view/822e471055270722192ef736.html 电脑可以识别 sd 卡手机无法识别 * (本教程只是本人实际操作方法,可以解决一部 ...

  6. Selenium WebDriver 常用API

    public class Demo1 { WebDriver driver; @BeforeMethod public void visit(){ //webdriver对象的声明 System.se ...

  7. Linux 初始化系统 systemd - journald 日志

    journalctl 中文手册 archlinux - journal systemd-journald 用于检索 systemd 的日志,是 systemd 自带的日志系统. 1. systemd- ...

  8. 学习Spring IOC控制反转和DI依赖注入总结

    30岁的小曹,20岁的身体,还在坚持在能力允许控制范围内22点睡觉,5点起床锻炼身体,好好学习,除了加班或者像今天这样的深夜,再一次写已经有X百万人写过的 spring Ioc 的总结博客. 一.IO ...

  9. Ubuntu下面怎么连接drcom校园网?(重庆大学实测可行)

    之前因为ubuntu下面不能连drcom接校园头疼了半天,我们学校自带的客户端成功运行了,但是还是不能上网.\ 于是我百度了半天,搜了一堆教程...因为技术太渣好多教程里面不会修改参数,然后都不能成功 ...

  10. Mysql基础篇(笔记)

    mysql数据库是由DB跟DBMS跟sql组成 DB 数据库仓库 DBMS 数据库管理系统 SQL 一门通用的数据库语言   数据库启动命令 : 关闭->net stop MySQL || 开启 ...