Finding Hotels

http://acm.hdu.edu.cn/showproblem.php?pid=5992

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 2180    Accepted Submission(s): 688

Problem Description
There are N hotels all over the world. Each hotel has a location and a price. M guests want to find a hotel with an acceptable price and a minimum distance from their locations. The distances are measured in Euclidean metric.
 
Input
The first line is the number of test cases. For each test case, the first line contains two integers N (N ≤ 200000) and M (M ≤ 20000). Each of the following N lines describes a hotel with 3 integers x (1 ≤ x ≤ N), y (1 ≤ y ≤ N) and c (1 ≤ c ≤ N), in which x and y are the coordinates of the hotel, c is its price. It is guaranteed that each of the N hotels has distinct x, distinct y, and distinct c. Then each of the following M lines describes the query of a guest with 3 integers x (1 ≤ x ≤ N), y (1 ≤ y ≤ N) and c (1 ≤ c ≤ N), in which x and y are the coordinates of the guest, c is the maximum acceptable price of the guest.
 
Output
For each guests query, output the hotel that the price is acceptable and is nearest to the guests location. If there are multiple hotels with acceptable prices and minimum distances, output the first one.
 
Sample Input
2
3 3
1 1 1
3 2 3
2 3 2
2 2 1
2 2 2
2 2 3
5 5
1 4 4
2 1 2
4 5 3
5 2 1
3 3 5
3 3 1
3 3 2
3 3 3
3 3 4
3 3 5
 
Sample Output
1 1 1
2 3 2
3 2 3
5 2 1
2 1 2
2 1 2
1 4 4
3 3 5
 
Source

结构体内用友元函数这题会T....

模板题

 #include<iostream>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define N 200005
using namespace std; int n,m,id;//n是点数,m是维度,id是当前切的维度 struct sair{
long long p[];
bool operator<(const sair &b)const{
return p[id]<b.p[id];
}
}_data[N],data[N<<],tt[N];
int flag[N<<]; priority_queue<pair<long long,sair> >Q; void build(int l,int r,int rt,int dep){
if(l>r) return;
flag[rt]=;
flag[rt<<]=flag[rt<<|]=-;
id=dep%m;
int mid=l+r>>;
nth_element(_data+l,_data+mid,_data+r+);
data[rt]=_data[mid];
build(l,mid-,rt<<,dep+);
build(mid+,r,rt<<|,dep+);
} void query(sair p,int k,int rt,int dep){
if(flag[rt]==-) return;
pair<long long,sair> cur(,data[rt]);//获得当前节点
for(int i=;i<m;i++){//计算当前节点到P点的距离
cur.first+=(cur.second.p[i]-p.p[i])*(cur.second.p[i]-p.p[i]);
}
int idx=dep%m;
int fg=;
int x=rt<<;
int y=rt<<|;
if(p.p[idx]>=data[rt].p[idx]) swap(x,y);
if(~flag[x]) query(p,k,x,dep+);
//开始回溯
if(Q.size()<k){
if(cur.second.p[]<=p.p[]){
Q.push(cur);
}
fg=;
}
else{
if(cur.first<=Q.top().first&&cur.second.p[]<=p.p[]){
if(cur.first==Q.top().first){
if(cur.second.p[]<Q.top().second.p[]){
Q.pop();
Q.push(cur);
}
}
else{
Q.pop();
Q.push(cur);
}
}
if(((p.p[idx]-data[rt].p[idx])*(p.p[idx]-data[rt].p[idx]))<Q.top().first){
fg=;
}
}
if(~flag[y]&&fg){
query(p,k,y,dep+);
}
} sair ans; int main(){
int T;
scanf("%d",&T);
int k;
while(T--){
scanf("%d %d",&n,&k);
m=;
for(int i=;i<=n;i++){
scanf("%lld %lld %lld",&_data[i].p[],&_data[i].p[],&_data[i].p[]);
_data[i].p[]=i;
}
build(,n,,);
sair tmp;
for(int i=;i<=k;i++){
while(!Q.empty()){
Q.pop();
}
scanf("%lld %lld %lld",&tmp.p[],&tmp.p[],&tmp.p[]);
tmp.p[]=0x3f3f3f3f;
query(tmp,,,);
ans=Q.top().second;
Q.pop();
printf("%lld %lld %lld\n",ans.p[],ans.p[],ans.p[]);
}
}
}

Finding Hotels的更多相关文章

  1. hdu-5992 Finding Hotels(kd-tree)

    题目链接: Finding Hotels Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 102400/102400 K (Java/ ...

  2. HDU5992 - Finding Hotels

    原题链接 Description 给出个二维平面上的点,每个点有权值.次询问,求所有权值小于等于的点中,距离坐标的欧几里得距离最小的点.如果有多个满足条件的点,输出最靠前的一个. Solution 拿 ...

  3. 2016 ICPC青岛站---k题 Finding Hotels(K-D树)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5992 Problem Description There are N hotels all over ...

  4. HDU 5992/nowcoder 207K - Finding Hotels - [KDTree]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5992 题目链接:https://www.nowcoder.com/acm/contest/207/K ...

  5. 【22.95%】【hdu 5992】Finding Hotels

    Problem Description There are N hotels all over the world. Each hotel has a location and a price. M ...

  6. HDU 5992 Finding Hotels(KD树)题解

    题意:n家旅店,每个旅店都有坐标x,y,每晚价钱z,m个客人,坐标x,y,钱c,问你每个客人最近且能住进去(非花最少钱)的旅店,一样近的选排名靠前的. 思路:KD树模板题 代码: #include&l ...

  7. 【HDU5992】Finding Hotels 【KD树】

    题意 给出n个酒店的坐标和价格,然后m个查询,每个查询给出一个人的坐标和能承受的最大价格,然后找出在他价格承受范围以内,距离他最近的宾馆,如果有多个,那么输出第一个 分析 kd树的模板题 #inclu ...

  8. 【kd-tree】hdu5992 Finding Hotels

    比较裸的kd-tree,但是比较考验剪枝. 貌似除了经典的矩形距离剪枝之外, 还必须加个剪枝是某个矩形内的最小价格如果大于价格限制的话,则剪枝. #include<cstdio> #inc ...

  9. Hdu-5992 2016ACM/ICPC亚洲区青岛站 K.Finding Hotels KDtree

    题面 题意:二维平面上有很多点,每个点有个权值,现在给你一个点(很多组),权值v,让你找到权值小于等于v的点中离这个点最近的,相同的输出id小的 题解:很裸的KDtree,但是查询的时候有2个小限制, ...

随机推荐

  1. 廖雪峰Java1-2Java程序基础-3整数运算

    1.四则运算规则 int i =(100 + 200) * (99 -88);//3300 int n = i + 9;//3309 //除法结果为整数 int q = n / 100;//33 // ...

  2. position和margin的绝对定位和相对定位

    电脑桌面清理干净之后,果然快了很多,桌面上的东西会占用内存,导致电脑变慢,以前我看到表姐的电脑桌面堆满了东西,我就在心里默默的鄙视不懂玩电脑的人,现在我竟然也养成了这种坏毛病..保存东西的时候放在桌面 ...

  3. 现在的 Linux 内核和 Linux 2.6 的内核有多大区别?

    作者:larmbr宇链接:https://www.zhihu.com/question/35484429/answer/62964898来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...

  4. 并发基础(四) java中线程的状态

    一.程的五种状态   线程的生命周期可以大致分为5种,但这种说法是比较旧的一种说法,有点过时了,或者更确切的来说,这是操作系统的说法,而不是java的说法.但对下面所说的六种状态的理解有所帮助,所以也 ...

  5. Java面向对象技术

    问题及答案来源自<Java程序员面试笔试宝典>第四章 Java基础知识 4.2面向对象技术 1.面向对象与面向过程有什么区别? 看下面一个实例即可: 面向过程就是分析出解决问题所需要的步骤 ...

  6. linux操作系统4 软件包管理

    知识内容: 1.软件包介绍 2.基本软件包安装 3.yum软件包管理 4.apt软件包管理 5.源码安装 一.软件包介绍 1.软件包分类 压缩包形式:类似.tar.gz结尾的文件(源码) rpm: r ...

  7. zend_soap做webservice的使用方法

      只用到zend_soap包中的Zend_Soap_Server,Zend_Soap_AutoDiscover和Zend_Soap_Client三个类 首先要注意ZF是调用php的soap扩展,所以 ...

  8. sqlserver查询---分配cpu等资源

    数据库资源按需分配 https://www.cnblogs.com/i6first/p/4138365.html https://blog.csdn.net/kk185800961/article/d ...

  9. XE6 任务栏 控件

    WIN7/WIN8 ONLY,鼠标放在任务栏上,预览程序界面,用此控件可以预览安装进度条. Taskbar1->ProgressMaxValue = 100;  Taskbar1->Pro ...

  10. 去除android手机浏览器中, 按住链接出现border的情况

    body{ -moz-user-select:none; -webkit-user-select:none; -webkit-tap-highlight-color:transparent; }