当前位置:网站首页>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;
}
边栏推荐
- node uses redis
- Couple Holding Hands [Greedy & Abstract]
- leetcode: 269. The Martian Dictionary
- 【LeetCode】矩阵模拟相关题目汇总
- E - Many Operations (bitwise consideration + dp thought to record the result after the operation
- 软件测试面试题:LoadRunner 分为哪三个模块?
- 【unity编译器扩展之模型动画拷贝】
- Software Testing Interview Questions: What's the Difference Between Manual Testing and Automated Testing?
- Software Testing Interview Questions: What aspects should be considered when designing test cases, i.e. what aspects should different test cases test against?
- 软件测试面试题:关于自动化测试工具?
猜你喜欢

TinyMCE禁用转义

Essential knowledge for entry-level 3D game modelers

oracle创建用户以后的权限问题

导入JankStats检测卡帧库遇到问题记录
![[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots](/img/fa/5bdc81b1ebfc22d31f42da34427f3e.png)
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots

redis可视化管理软件Redis Desktop Manager2022

Redis visual management software Redis Desktop Manager2022

SV class virtual method of polymorphism

测试经理要不要做测试执行?

leetcode:266. 回文全排列
随机推荐
【unity编译器扩展之模型动画拷贝】
2022牛客多校训练第二场 H题 Take the Elevator
2022杭电多校第三场 K题 Taxi
leetcode经典例题——单词拆分
软件测试面试题:关于自动化测试工具?
node uses redis
软件测试面试题:什么是软件测试?软件测试的目的与原则?
软件测试面试题:软件验收测试的合格通过准则?
动态上传jar包热部署
matlab中rcosdesign函数升余弦滚降成型滤波器
Software Testing Interview Questions: About Automated Testing Tools?
Will domestic websites use Hong Kong servers be blocked?
Software Testing Interview Questions: What's the Difference Between Manual Testing and Automated Testing?
what?测试/开发程序员要被淘汰了?年龄40被砍到了32?一瞬间,有点缓不过神来......
Software testing interview questions: What are the three modules of LoadRunner?
How to automatically push my new articles to my fans (very simple, can't learn to hit me)
tiup update
软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?
More than 2022 cattle school training topic Link with the second L Level Editor I
软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?