当前位置:网站首页>2022 Hangzhou Electric Power Multi-School Session 3 K Question Taxi
2022 Hangzhou Electric Power Multi-School Session 3 K Question Taxi
2022-08-05 00:23:00 【Rain Sure】
题目链接
题目大意
Given our two-dimensional plane n n n个点,We are from the current point ( x , y ) (x, y) (x,y),前往第 i i i个点,Can reduce the cost m i n ( ( ∣ x − x i ∣ + ∣ y − y i ∣ ) , w i ) min((|x - x_i | + |y - y_i |), w_i) min((∣x−xi∣+∣y−yi∣),wi),给定我们 q q q个询问,Every time give us a 2 d plane of a point,We need to calculate the maximum to reduce the cost of.
题解
Mainly with the help of a magical transformation,我也没遇到过,Game when my teammates told me~
We need pretreatment out all points of the four most value,When calculated in this way can O ( 1 ) O(1) O(1)Time was calculated.
We according to each point w w w值从小到大进行排序,Then the binary label,Then calculate the maximum distance d d d,通过 d d d和 w w w进行判断,The next step to the left or right,It's important to note that we need to record the value in the process of binary.具体细节看代码,See the code will understand some.
代码
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const int maxn = 100010, inf = 1e18;
typedef struct node
{
int x, y, w;
bool operator < (const struct node &t) const{
return w < t.w;
}
}Node;
Node points[maxn];
int a[maxn], b[maxn], c[maxn], d[maxn];
int n, q;
int sx, sy;
int res;
bool check(int mid)
{
int t = -inf;
int w = points[mid].w;
t = max(t, sx + sy + a[mid]);
t = max(t, sx - sy + b[mid]);
t = max(t, -sx + sy + c[mid]);
t = max(t, -sx - sy + d[mid]);
res = max(res, min(w, t));
return w <= t;
}
signed main()
{
IOS;
int t; cin >> t;
while(t --){
cin >> n >> q;
for(int i = 0; i < n; i ++){
int x, y, w; cin >> x >> y >> w;
points[i] = {
x, y, w};
}
sort(points, points + n);
a[n] = b[n] = c[n] = d[n] = -inf;
for(int i = n - 1; i >= 0; i --){
a[i] = max(a[i + 1], -points[i].x - points[i].y);
b[i] = max(b[i + 1], -points[i].x + points[i].y);
c[i] = max(c[i + 1], points[i].x - points[i].y);
d[i] = max(d[i + 1], points[i].x + points[i].y);
}
while(q --){
res = -inf;
cin >> sx >> sy;
int l = 0, r = n - 1;
while(l < r){
int mid = l + r + 1 >> 1;
if(check(mid)) l = mid;
else r = mid - 1;;
}
check(l);
cout << res << endl;
}
}
return 0;
}
边栏推荐
- oracle创建用户
- 软件质量评估的通用模型
- 2022牛客多校训练第二场 J题 Link with Arithmetic Progression
- could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
- 2022多校第二场 K题 Link with Bracket Sequence I
- 进程间通信和线程间通信
- gorm的Raw与scan
- 2022牛客多校第三场 A Ancestor
- Software Testing Interview Questions: About Automated Testing Tools?
- 【云原生--Kubernetes】Pod控制器
猜你喜欢
随机推荐
Cloud native - Kubernetes 】 【 scheduling constraints
Will domestic websites use Hong Kong servers be blocked?
gorm联表查询-实战
软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?
2022牛客多校第三场 J题 Journey
tiup update
[Cloud Native--Kubernetes] Pod Controller
性能测试如何准备测试数据
2022 Hangzhou Electric Multi-School 1004 Ball
【Unity编译器扩展之进度条】
【LeetCode】滑动窗口题解汇总
leetcode: 266. All Palindromic Permutations
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
QSunSync 七牛云文件同步工具,批量上传
机器学习(公式推导与代码实现)--sklearn机器学习库
IDEA file encoding modification
图解 Canvas 入门
倒计时1天!8月2日—4日与你聊聊开源与就业那些事!
RK3399平台开发系列讲解(内核调试篇)2.50、嵌入式产品启动速度优化
电赛必备技能___定时ADC+DMA+串口通信