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. JVM插码之五:Java agent+ASM实战--监控所有方法执行时间

    本文建立在对instrumentation和agent有初步的了解的前提下阅读,关于这2个类的讲解在其它文章中. 这是一个maven项目,pom中需要的配置,lib中有asm的jar包 pom.xml ...

  2. Vue引用其他组件,但组件某些部分不需要时的简单处理

    项目开发时,我们会把多个地方重复使用的模块抽象成组件,提供给大家一起使用,但是使用组件的时候偶尔会遇见一些问题,比如说组件里只有某些东西自己并不需要,这个时候我们可以对组件进行简单的修改,而不影响其他 ...

  3. windows,linux下SVN实现自动更新WEB目录

    通过SVN进行版本库管理,每次提交后,都要在SVN服务器更新最新上传的版本到WEB目录进行同步.操作比较烦琐,而且效率也低.使用SVN钩子脚本进行WEB目录同步,可很好的解决这方面的问题.由于测试机器 ...

  4. 关于input=file的用法

    <input type="file"/>这个东西是用来上传图片用的. 1,但是存在一下问题但是在在各个浏览器下的显示是不一样的 IE下: IE之外的浏览器: 2.如果不 ...

  5. SDOI 2017 天才黑客

    /* 根据claris的 博客以及 beginend 的博客来写的 首先考虑如何求出最短路 可以从样例看出 路径是从边走到边的, 所以我们将边看作点 有共同端点的两边之间 互相连边, 边权为lcp. ...

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

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

  7. VS2015+Opencv半永久配置

    电脑W7 64位+VS2015+opencv3.0 刚开始学习opeencv很麻烦,配置的问题都弄了好久,一旦重装又出现很多问题,在网上看了一个论坛说的永久配置,特意记录一下! 第一步:下载openc ...

  8. svn完整搭建

    安装软件 # yum install httpd mod_dav_svn subversion mod_ssl 查看是否安装成功   #svn --version 如果出现版本号如 则说明svn安装成 ...

  9. python入门-字典

    1 python是使用{}来表示字典 字典是一系列的键值对 alien_0={} 2 访问字典中的值 new_point = alien_0['point'] print("you just ...

  10. 1.urlencoder和urldecoder的使用

    今天传url的时候乱码了.先说情形,url中有searchText=中文的情形,后台new String(searchText.getBytes(ISO-8859-1),"gbk" ...