Finding Hotels
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
结构体内用友元函数这题会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的更多相关文章
- hdu-5992 Finding Hotels(kd-tree)
题目链接: Finding Hotels Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/ ...
- HDU5992 - Finding Hotels
原题链接 Description 给出个二维平面上的点,每个点有权值.次询问,求所有权值小于等于的点中,距离坐标的欧几里得距离最小的点.如果有多个满足条件的点,输出最靠前的一个. Solution 拿 ...
- 2016 ICPC青岛站---k题 Finding Hotels(K-D树)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5992 Problem Description There are N hotels all over ...
- HDU 5992/nowcoder 207K - Finding Hotels - [KDTree]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5992 题目链接:https://www.nowcoder.com/acm/contest/207/K ...
- 【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 ...
- HDU 5992 Finding Hotels(KD树)题解
题意:n家旅店,每个旅店都有坐标x,y,每晚价钱z,m个客人,坐标x,y,钱c,问你每个客人最近且能住进去(非花最少钱)的旅店,一样近的选排名靠前的. 思路:KD树模板题 代码: #include&l ...
- 【HDU5992】Finding Hotels 【KD树】
题意 给出n个酒店的坐标和价格,然后m个查询,每个查询给出一个人的坐标和能承受的最大价格,然后找出在他价格承受范围以内,距离他最近的宾馆,如果有多个,那么输出第一个 分析 kd树的模板题 #inclu ...
- 【kd-tree】hdu5992 Finding Hotels
比较裸的kd-tree,但是比较考验剪枝. 貌似除了经典的矩形距离剪枝之外, 还必须加个剪枝是某个矩形内的最小价格如果大于价格限制的话,则剪枝. #include<cstdio> #inc ...
- Hdu-5992 2016ACM/ICPC亚洲区青岛站 K.Finding Hotels KDtree
题面 题意:二维平面上有很多点,每个点有个权值,现在给你一个点(很多组),权值v,让你找到权值小于等于v的点中离这个点最近的,相同的输出id小的 题解:很裸的KDtree,但是查询的时候有2个小限制, ...
随机推荐
- 错误:Unsupported major.minor version 51.0(jdk版本错误)
Java.lang.UnsupportedClassVersionError: org/apache/nutch/crawl/Crawl3 : Unsupported major.minor vers ...
- dede:channel的type改为son,currentstyle当前样式就不起作用
我在修改得闲佬设计作品展示列表页的时候,遇到一个问题,就是channel的type改为son时,currentstyle属性不起作用,试了好久都没办法,后来上网找资料,就找到了解决方法,记录一下. ...
- call和apply,bind的区别专讲
可以干什么? 改变函数内的this指向: 什么时候使用? 构造函数使用this 为什么使用? 为了生成对象 类(函数名不可以带括号).call() 因为this指向对象,所以call的第一个 ...
- 1077 Kuchiguse (20 分)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- JNDI的学习与使用
JNDI(Java Naming and Directory Interface,Java命名和目录接口)是一组在Java应用中访问命名和目录服务的API.命名服务将名称和对象联系起来,使得我们可以用 ...
- mvc和mtv
Java中MVC详解以及优缺点总结 概念: MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一 ...
- PCIe Max_Payload_Size 和 Max_Read_Request_Size
最近PCIe在SSDFans上镜率挺高,那我们来聊两句MAX_READ_REQUEST_SIZE 和MAX_PAYLOAD_SIZE. 这两个东西都在PCIe Capability Structure ...
- oracle报ora-12519错误
具体信息如下: ora-12519 tns:no appropriate service handler found the connection descriptor used by the cli ...
- Spring_JAP_CXF_maven
发送 pom,xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://ww ...
- leetcode743
class Solution { public: int networkDelayTime(vector<vector<int>>& times, int N, int ...