当前位置:网站首页>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;
}
边栏推荐
- 简单介绍BASE64Encoder的使用
- Séparateur JS3 de niuke
- How to create a new page for SAP Spartacus storefront
- Configure lamp+supervisor
- 2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
- ceph 原理
- Sword finger offer 24 Reverse linked list
- Chmod command principle and usage details [easy to understand]
- 关于我
- Update iteration of cloud communication interface -- the official launch of subail API V4
猜你喜欢
剑指 Offer 25. 合并两个排序的链表
深度之眼(三)——矩阵的行列式
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
A case study of college entrance examination prediction based on multivariate time series
Microservice architecture practice: Construction of scalable distributed database cluster
剑指 Offer 24. 反转链表
A few lines of code to complete RPC service registration and discovery
13、Darknet YOLO3
Baobab's gem IPO was terminated: Tang Guangyu once planned to raise 1.8 billion to control 47% of the equity
阿里天池SQL学习笔记——DAY3
随机推荐
剑指 Offer 25. 合并两个排序的链表
【目标跟踪】|数据集汇总
How to create a new page for SAP Spartacus storefront
HBuilderX运行到手机或模拟器提示没有找到设备
详细介绍scrollIntoView()方法属性
Microservice architecture practice: using Jenkins to realize automatic construction
SAP Commerce Cloud 架构概述
871. Minimum refueling times
Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
什么是敏捷开发流程
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
云通信接口更新迭代——SUBMAIL API V4正式上线
PCL知识点——体素化网格方法对点云进行下采样
Alibaba Tianchi SQL learning notes - Day3
ceph 原理
什么是软件开发中的 green field 和 brown field 模式 - 绿地开发和棕地开发
vector的底层模拟实现
Win10 system uses pip to install juypter notebook process record (installed on a disk other than the system disk)
MATLAB中nexttile函数使用
【GAMES101】作业4 Bézier 曲线