当前位置:网站首页>uva1169
uva1169
2022-07-02 15:18:00 【小刀刺大熊】
#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 100010;
int x[maxn] = {
0 }, y[maxn] = {
0}, z, n,c;
int dis[maxn] = {
0 }, w[maxn] = {
0 }, org[maxn] = {
0 };
int q[maxn], d[maxn];
int fun(int i) {
return d[i] - dis[i + 1] + org[i + 1];
}
int main()
{
int t;
cin >> t;
while (t--) {
cin >> c >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i] >> z;
org[i] = abs(x[i]) + abs(y[i]);
w[i] = w[i - 1] + z;
dis[i] = dis[i - 1] + abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
}
int front = 1, rear = 1;
for (int i = 1; i <= n; i++) {
while (front <= rear && w[i] - w[q[front]] > c)++front;
d[i] = fun(q[front]) + dis[i] + org[i];
while (front <= rear && fun(i) <= fun(q[rear]))--rear;
q[++rear] = i;
}
cout << d[n] << endl;
if (t)cout << endl;
}
return 0;
}
边栏推荐
猜你喜欢

13、Darknet YOLO3

Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!

Eye of depth (III) -- determinant of matrix

HBuilderX运行到手机或模拟器提示没有找到设备

vector的底层模拟实现

Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
![[web technology] 1233 seconds understand web component](/img/42/c98d8112dc4ece0a92dda97647be5c.jpg)
[web technology] 1233 seconds understand web component

After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning

剑指 Offer 24. 反转链表

What if the default browser cannot be set?
随机推荐
书包网小说多线程爬虫[通俗易懂]
Common SQL statements (complete example)
The difference between class and getClass ()
剑指 Offer 24. 反转链表
Flutter: 动作反馈
ROS知识点——消息过滤器 ( message_filters)
SAP commerce Cloud Architecture Overview
Eye of depth (II) -- matrix and its basic operations
QStyle实现自绘界面项目实战(二)
What is agile development process
CEPH principle
线性规划例题 投资的收益与风险
什么是软件开发中的 green field 和 brown field 模式 - 绿地开发和棕地开发
The difference of message mechanism between MFC and QT
Experience home office, feel the completion of the project | community essay solicitation
从收集到输出:盘点那些强大的知识管理工具——优秀笔记软件盘点(四)
Sword finger offer 22 The penultimate node in the linked list
JS20 数组扁平化
【GAMES101】作业4 Bézier 曲线
Geoserver: publishing PostGIS data sources