当前位置:网站首页>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;
}
边栏推荐
- 软件测试面试题:一套完整的测试应该由哪些阶段组成?
- 电赛必备技能___定时ADC+DMA+串口通信
- E - Distance Sequence (前缀和优化dp
- leetcode:267. 回文排列 II
- 标识符、关键字、常量 和变量(C语言)
- Software Testing Interview Questions: What do you think about software process improvement? Is there something that needs improvement in the enterprise you have worked for? What do you expect the idea
- 10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
- 【LeetCode】双指针题解汇总
- leetcode经典例题——单词拆分
- How to automatically push my new articles to my fans (very simple, can't learn to hit me)
猜你喜欢

STC89C52RC的P4口的应用问题
![Couple Holding Hands [Greedy & Abstract]](/img/7d/1cafc000dc58f1c5e2e92150be7953.png)
Couple Holding Hands [Greedy & Abstract]

【论文笔记】—低照度图像增强—Unsupervised—EnlightenGAN—2019-TIP

国内网站用香港服务器会被封吗?

标识符、关键字、常量 和变量(C语言)

Getting started with 3D modeling for games, what modeling software can I choose?

电子行业MES管理系统的主要功能与用途

英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps

性能测试如何准备测试数据

【Valentine's Day special effects】--Canvas realizes full screen love
随机推荐
图解 Canvas 入门
"No title"
leetcode: 269. The Martian Dictionary
leetcode经典例题——单词拆分
软件测试面试题:什么是软件测试?软件测试的目的与原则?
tiup telemetry
2022牛客多校训练第二场 L题 Link with Level Editor I
Three tips for you to successfully get started with 3D modeling
国内网站用香港服务器会被封吗?
软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?
【无标题】
翁恺C语言程序设计网课笔记合集
STC89C52RC的P4口的应用问题
2022杭电多校第三场 K题 Taxi
Redis visual management software Redis Desktop Manager2022
E - Distance Sequence (prefix and optimized dp
软件测试面试题:测试生命周期,测试过程分为几个阶段,以及各阶段的含义及使用的方法?
tiup uninstall
简单的顺序结构程序(C语言)
2022 Multi-school Second Session K Question Link with Bracket Sequence I