当前位置:网站首页>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;
}
边栏推荐
- chrome瀏覽器快速訪問stackoverflow
- Explanation of traceroute command
- em120.gige.h
- Solution to the problem that the easycvr kernel of intelligent video analysis platform cannot be started as a service
- 简单介绍BASE64Encoder的使用
- 链表求和[dummy+尾插法+函数处理链表引用常见坑位]
- LeetCode:1380. Lucky number in matrix -- simple
- 嵌入式 ~ 介绍
- executescalar mysql_ ExecuteScalar()
- Configure lamp+supervisor
猜你喜欢
Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
每日一题——小乐乐改数字
Platform management background and business menu resource management: business permissions and menu resource management design
freemarker+poi实现动态生成excel文件及解析excel文件
阿里天池SQL学习笔记——DAY3
[how is the network connected] Chapter 4 explores access networks and network operators
Experience home office, feel the completion of the project | community essay solicitation
RK1126平台项目总结
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
HBuilderX运行到手机或模拟器提示没有找到设备
随机推荐
Vscode + eslint configuration
Ssm+ wechat applet to realize property management system
The construction of scalable distributed database cluster and the partition design of oneproxy sub database
LeetCode:1380. Lucky number in matrix -- simple
Timing / counter of 32 and 51 single chip microcomputer
阿里天池SQL学习笔记——DAY3
How to create a new page for SAP Spartacus storefront
Shutter: action feedback
云通信接口更新迭代——SUBMAIL API V4正式上线
VScode知识点——常见报错
牛客 JS3 分隔符
[非线性控制理论]8_三种鲁棒控制器的比较
维护万星开源向量数据库是什么体验
Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!
Meanings of SNAT, DNAT and masquerade in iptables
Use of nexttile function in MATLAB
Five reasons to choose SAP Spartacus as the implementation framework of SAP commerce cloud storefront
What are the green field and brown field models in software development - green field development and brown field development
Introduction to Hisilicon hi3798mv100 set top box chip [easy to understand]
例题 非线性整数规划