当前位置:网站首页>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;
}
边栏推荐
- Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程
- ROS knowledge points -- the difference between ros:: nodehandle N and NH ("~")
- Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia
- 如何给 SAP Spartacus Storefront 创建新的页面
- Eye of depth (II) -- matrix and its basic operations
- IDEA2021.1 安装教程
- vector的底层模拟实现
- The beginning of life
- chmod命令原理及用法详解[通俗易懂]
- TCP拥塞控制详解 | 2. 背景
猜你喜欢

About me

默认浏览器设置不了怎么办?

si446使用记录(二):使用WDS3生成头文件

Green bamboo biological sprint Hong Kong stocks: loss of more than 500million during the year, tiger medicine and Beijing Yizhuang are shareholders

Qstype implementation of self drawing interface project practice (II)

Sword finger offer 24 Reverse linked list

TCP拥塞控制详解 | 2. 背景
![[非线性控制理论]8_三种鲁棒控制器的比较](/img/a8/03ed363659a0a067c2f1934457c106.png)
[非线性控制理论]8_三种鲁棒控制器的比较

Experience home office, feel the completion of the project | community essay solicitation

13、Darknet YOLO3
随机推荐
什么是软件开发中的 green field 和 brown field 模式 - 绿地开发和棕地开发
Explanation of traceroute command
traceroute命令讲解
SSB threshold_ SSB modulation "suggestions collection"
Solving simple differential equations
ThreadLocal
常用SQL语句(完整范例)
Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
云通信接口更新迭代——SUBMAIL API V4正式上线
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
Introduce the scrollintoview() method attribute in detail
Eth data set download and related problems
HBuilderX运行到手机或模拟器提示没有找到设备
Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers
MATLAB中nexttile函数使用
Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia
PCL knowledge points - voxelized grid method for down sampling of point clouds
JS20 array flattening
VScode知识点——常见报错