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技巧和方法:第二篇是一 ...
随机推荐
- 计算一段日期内的周末天数的php代码(星期六,星期日总和)
代码如下: /*| Author: Yang Yu <niceses@gmail.com>| @param char|int $start_date 一个有效的日期格式,例如:200910 ...
- 20180813-Java 重写(Override)与重载(Overload)
Java 重写(Override)与重载(Overload) class Animal{ public void move(){ System.out.println("动物可以移动&quo ...
- UE4 中的Blutilities
该功能是为编辑器中的简单扩展功能而设置的. 一般而言用蓝图在编辑器中做功能扩展都会用到Construction Script,但该功能有一些缺陷: 首先在actor发生任何变化(包括Transform ...
- 谜之WA
完全k叉树 谜之WA #include<bits/stdc++.h> using namespace std; typedef unsigned long long ll; ll k,n; ...
- LR分析Analysis火车票
一.分析结果 1 研究 Vuser 的行为(F:\JMeter\0Tutorial-SCR\机票预订\机票_analysis-session) 筛选该图,仅查看所有 Vuser 同时运行的时间段 右键 ...
- python2.7+RobotFramework的UI自动化环境搭建
robotFramework是一种比较常见的自动化测试框架,此篇记录环境搭建 目录 1.软件准备 2.执行安装 1.软件准备 python-2.7.15.amd64.msi ...
- python web自动化测试框架搭建(功能&接口)——接口用例实现
测试用例基类: # coding=utf-8 import unittest import Logger log = Logger.Loger() class BaseCase(unittest.Te ...
- 爬虫中GET方法应用基本模型
根据get方法,更改界面url从而获取信息 GET请求URL附带查询参数 POST请求保存在form表单中 分析百度贴吧url特点: 分析url https://tieba.baidu.com/f是贴 ...
- 笨方法学Python 错误记录
ex8:忘记输入“空格”ex9:忘记输入“冒号”ex14:%前后要空格,否则errorex21:多个函数嵌套,漏写括号)ex24:%d,漏写d,导致程序错误:"""之间的 ...
- Go-Mutex互斥量
先来看一段go1.12.5中Mutex的源码: // Copyright 2009 The Go Authors. All rights reserved. // Use of this source ...