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技巧和方法:第二篇是一 ...
随机推荐
- (1)消灭初级程序员常用的多层if-else嵌套--------------【表驱动法】
表驱动法 1.相信很多刚从事工作的程序员或一些初级程序员在写代码的时候会出现对一些逻辑判断写成多层if-else嵌套的经历,这种方式在一些简单的层次中运用起来确实可行,但对于一些大型项目逻辑判断比较多 ...
- HDU 1003 解题报告
问题描述:求最大连续字串 分析:一道简单的DP,状态转移方程是d[i] = ( d[i-1]+a[i] > a[i] ) ? d[i-1]+a[i] : a[i] d[i]表示以第i个数字结尾的 ...
- java sftp.exec无法执行mv命令
编写java程序过程中,sftp上传下载建目录删除文件都可以,就是备份不行. 分析原因如下: 1.如果用的同一个用户,即sftp用户来通过 exec(ssh连接) 执行mv命令,那极有可能是在搭建sf ...
- indy idhttpserver有关下载的两个问题
http://aawwmate.blog.163.com/blog/static/77528256201092733950315/ indy idhttpserver有关下载的两个问题 2010-10 ...
- hibernate搭建及其增删改查
一.jar包 最基础的hibernatejar包,以及数据库驱动的jar包 二.数据库 t_user表 id int 主键 自动增长 name varchar() 三.配置文件 <?xml ve ...
- 查看mysql 的版本信息
在进入mysql的情况下 在终端的情况下:
- jmeter对响应数据做断言
单独校验某个接口中的某个字段时,断言就相当于检查点 添加http请求,输入路径url
- docker安装及基本命令
Ubuntu安装docker sudo apt-get install docker.io Centos安装docker # 更新系统软件包 yum -y upgrade # 官方下载地址 curl ...
- thymeleaf 下拉选框回显选中
参考了许多,最后以这种方法实现了.尽管有些愚蠢,初步学习阶段.不知道为什么用th:field会报错.网上有些是用field来解决回显问题的. <select name="positio ...
- python的小介绍
Python简介 龟叔 优美.清晰.简单 主要应用领域: 云计算 WEB开发 科学技术.人工智能 系统运维 爬虫 金融量化分析 图形GUI 游戏 Python发展史 1989年,Guido开始写Pyt ...