当前位置:网站首页>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;
}
边栏推荐
- Sword finger offer 22 The penultimate node in the linked list
- 深度之眼(二)——矩阵及其基本运算
- Timing / counter of 32 and 51 single chip microcomputer
- 871. Minimum refueling times
- helm kubernetes包管理工具
- Un an à dix ans
- Dstat use [easy to understand]
- 最长无重复子数组
- From collection to output: inventory those powerful knowledge management tools - inventory of excellent note taking software (4)
- SAP Commerce Cloud 架构概述
猜你喜欢

Connect Porsche and 3PL EDI cases
![链表求和[dummy+尾插法+函数处理链表引用常见坑位]](/img/08/30e8ca2376104d648a82dca8a72c42.png)
链表求和[dummy+尾插法+函数处理链表引用常见坑位]

QWebEngineView崩溃及替代方案

剑指 Offer 22. 链表中倒数第k个节点

Eye of depth (II) -- matrix and its basic operations

ThreadLocal

The construction of scalable distributed database cluster and the partition design of oneproxy sub database

Example nonlinear integer programming

Si446 usage record (II): generate header files using wds3

Simple linear programming problem
随机推荐
13、Darknet YOLO3
IPtables中SNAT、DNAT和MASQUERADE的含义
HBuilderX运行到手机或模拟器提示没有找到设备
871. Minimum refueling times
Eth data set download and related problems
Blog theme "text" summer fresh Special Edition
Eye of depth (III) -- determinant of matrix
Vscode + eslint configuration
ssb门限_SSB调制「建议收藏」
Meanings of SNAT, DNAT and masquerade in iptables
chrome浏览器快速访问stackoverflow
常用SQL语句(完整范例)
JS20 数组扁平化
The beginning of life
默认浏览器设置不了怎么办?
Uniapp H5 page calls wechat payment
Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
Visibilitychange – refresh the page data when the specified tab is visible
Sword finger offer 26 Substructure of tree
A case study of college entrance examination prediction based on multivariate time series