日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

二分+思维点点之间最大距离

發(fā)布時(shí)間:2023/12/20 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 二分+思维点点之间最大距离 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Problem Description

There are?nn?towns in Byteland, labeled by?1,2,\dots,n1,2,…,n. The?ii-th town's location is?(x_i,y_i)(xi?,yi?). Little Q got a taxi VIP card, he can use the VIP card to cut down the taxi fare. Formally, assume Little Q is at?(x',y')(x′,y′), if he calls a taxi to drive him to the?kk-th town, the VIP card will reduce?\min(|x'-x_k|+|y'-y_k|,w_k)min(∣x′?xk?∣+∣y′?yk?∣,wk?)?dollars.

Little Q wants to make full use of his VIP card. He will give you?qq?queries, in each query you will be given his location, and you need to choose a town such that the VIP card will reduce the most taxi fare.

Input

The first line contains a single integer?TT?(1 \leq T \leq 1001≤T≤100), the number of test cases. For each test case:

The first line contains two integers?nn?and?qq?(1 \leq n,q \leq 100,0001≤n,q≤100,000), denoting the number of towns and the number of queries.

Each of the following?nn?lines contains three integers?x_ixi?,?y_iyi??and?w_iwi??(1 \leq x_i,y_i,w_i \leq 10^91≤xi?,yi?,wi?≤109), describing a town.

Each of the following?qq?lines contains two integers?x'x′?and?y'y′?(1 \leq x',y' \leq 10^91≤x′,y′≤109), describing a query.

It is guaranteed that the sum of all?nn?is at most?500,000500,000, and the sum of all?qq?is at most?500,000500,000.

Output

For each query, print a single line containing an integer, denoting the maximum possible reduced taxi fare.

#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; const int N=1e5+5,INF=2e9; struct node{int x,y,w;bool operator < (const node &b){return w<b.w;} }p[N]; int a[N],b[N],c[N],d[N]; int xx,yy; int ans=0; bool pd(int mid) {int mxv=0;mxv=max(mxv,xx+yy+a[mid]);mxv=max(mxv,xx-yy+b[mid]);mxv=max(mxv,-xx+yy+c[mid]);mxv=max(mxv,-xx-yy+d[mid]);ans=max(ans,min(mxv,p[mid].w));return mxv>=p[mid].w; } void solve() {int n,q;scanf("%d%d",&n,&q);for(int i=1;i<=n;i++){int x,y,w;scanf("%d%d%d",&x,&y,&w);p[i]={x,y,w};}sort(p+1,p+1+n);a[n+1]=b[n+1]=c[n+1]=d[n+1]=-INF;for(int i=n;i>=1;i--){a[i]=max(a[i+1],-p[i].x-p[i].y);b[i]=max(b[i+1],-p[i].x+p[i].y);c[i]=max(c[i+1],p[i].x-p[i].y);d[i]=max(d[i+1],p[i].x+p[i].y);}while(q--){scanf("%d%d",&xx,&yy);ans=0;int l=1,r=n;while(l<=r){int m=(l+r)/2;if(pd(m)) l=m+1;else r=m-1;}printf("%d\n",ans);}} int main() {int t;scanf("%d",&t);while(t--){solve();} }

總結(jié)

以上是生活随笔為你收集整理的二分+思维点点之间最大距离的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。