当前位置:网站首页>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;
}
边栏推荐
- Mysql_12 多表查询
- More than 2022 cattle school training topic Link with the second L Level Editor I
- 软件测试面试题:您如何看待软件过程改进?在您曾经工作过的企业中,是否有一些需要改进的东西呢?您期望的理想的测试人员的工作环境是怎样的?
- tiup status
- The applicable scenarios and common product types of the KT148A electronic voice chip ic solution
- gorm joint table query - actual combat
- oracle创建用户以后的权限问题
- 子连接中的参数传递
- tensor.nozero(), mask, [mask]
- SV 类的虚方法 多态
猜你喜欢

STC89C52RC的P4口的应用问题

Senior game modelers tell newbies, what are the necessary software for game scene modelers?

oracle创建表空间

10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻

进程间通信和线程间通信

【Valentine's Day special effects】--Canvas realizes full screen love

gorm联表查询-实战

could not build server_names_hash, you should increase server_names_hash_bucket_size: 32

翁恺C语言程序设计网课笔记合集

软件质量评估的通用模型
随机推荐
Zombie and orphan processes
Software Testing Interview Questions: What's the Difference Between Manual Testing and Automated Testing?
英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps
2022牛客多校第三场 J题 Journey
怎样进行在不改变主线程执行的时候,进行日志的记录
redis可视化管理软件Redis Desktop Manager2022
E - Distance Sequence (前缀和优化dp
tiup telemetry
导入JankStats检测卡帧库遇到问题记录
【LeetCode】矩阵模拟相关题目汇总
日志(logging模块)
TinyMCE禁用转义
#yyds dry goods inventory #Switching equipment serious packet loss troubleshooting
2022杭电多校第三场 L题 Two Permutations
"Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?
Redis visual management software Redis Desktop Manager2022
【Unity编译器扩展之进度条】
元宇宙:未来我们的每一个日常行为是否都能成为赚钱工具?
canvas Gaussian blur effect
D - I Hate Non-integer Number (count of selected number dp