当前位置:网站首页>uva1169
uva1169
2022-07-02 17:42:00 【Stab the bear with a knife】
#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;
}
边栏推荐
- What is agile development process
- How to create a new page for SAP Spartacus storefront
- No such file or directory: ‘/tmp/tmpxxx/tmpxxx.py‘
- The bottom simulation implementation of vector
- IDEA2021.1 安装教程
- VScode知识点——常见报错
- Win10 system uses pip to install juypter notebook process record (installed on a disk other than the system disk)
- IPtables中SNAT、DNAT和MASQUERADE的含义
- Chmod command principle and usage details [easy to understand]
- Update iteration of cloud communication interface -- the official launch of subail API V4
猜你喜欢

Modbus协议通信异常

维护万星开源向量数据库是什么体验

智能水电表能耗监测云平台

VirtualLab基础实验教程-7.偏振(2)

阿里天池SQL学习笔记——DAY3

Alibaba Tianchi SQL learning notes - Day3

The bottom simulation implementation of vector

LeetCode:1380. Lucky number in matrix -- simple

Microservice architecture practice: Construction of highly available distributed file system fastdfs architecture

Si446 usage record (II): generate header files using wds3
随机推荐
ROS knowledge point - message_filters
【GAMES101】作业4 Bézier 曲线
Five reasons to choose SAP Spartacus as the implementation framework of SAP commerce cloud storefront
牛客JS2 文件扩展名
例题 非线性整数规划
ROS knowledge points -- the difference between ros:: nodehandle N and NH ("~")
Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
每日一题——倒置字符串
将您的基于 Accelerator 的 SAP Commerce Cloud Storefront 迁移到 Spartacus
Meanings of SNAT, DNAT and masquerade in iptables
How openharmony starts fa (local and remote)
LeetCode:1380. Lucky number in matrix -- simple
POJ - 1458 Common Subsequence(最长公共子序列)
Dstat use [easy to understand]
Solving simple differential equations
维护万星开源向量数据库是什么体验
简单介绍BASE64Encoder的使用
Si446 usage record (I): basic data acquisition
IPtables中SNAT、DNAT和MASQUERADE的含义
The beginning of life