当前位置:网站首页>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;
}
边栏推荐
- 泡椒凤爪制作教程
- Niuke js3 separator
- ssb门限_SSB调制「建议收藏」
- How to create a new page for SAP Spartacus storefront
- Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
- HBuilderX运行到手机或模拟器提示没有找到设备
- After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
- dstat使用[通俗易懂]
- 阿里天池SQL学习笔记——DAY3
- Meanings of SNAT, DNAT and masquerade in iptables
猜你喜欢
871. 最低加油次数
ETH数据集下载及相关问题
例题 非线性整数规划
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
Eye of depth (II) -- matrix and its basic operations
How to transfer business data with BorgWarner through EDI?
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
ThreadLocal
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
随机推荐
ssb门限_SSB调制「建议收藏」
ceph 原理
Blog theme "text" summer fresh Special Edition
2022 interview questions
visibilitychange – 指定标签页可见时,刷新页面数据
Introduce the scrollintoview() method attribute in detail
LeetCode:1380. Lucky number in matrix -- simple
Introduction to nexus and detailed tutorial of Xiaobai using idea to package and upload to nexus3 private server
ThreadLocal
[非线性控制理论]7_High gain and High Frequency
ETH数据集下载及相关问题
Qwebengineview crash and alternatives
关于我
IDEA2021.1 安装教程
剑指 Offer 26. 树的子结构
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
Microservice architecture practice: using Jenkins to realize automatic construction
Microservice architecture practice: Construction of highly available distributed file system fastdfs architecture
CEPH principle
A few lines of code to complete RPC service registration and discovery