当前位置:网站首页>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;
}
边栏推荐
- Helm kubernetes package management tool
- Meanings of SNAT, DNAT and masquerade in iptables
- Making tutorial of chicken feet with pickled peppers
- Si446 usage record (II): generate header files using wds3
- List summation [dummy+ tail interpolation + function processing list reference common pit]
- Income and risk of linear programming example investment
- The difference of message mechanism between MFC and QT
- IDEA2021.1 安装教程
- [comment le réseau se connecte] chapitre 6: demande d'accès au serveur et réponse au client (terminé)
- Simple linear programming problem
猜你喜欢
![[非线性控制理论]8_三种鲁棒控制器的比较](/img/a8/03ed363659a0a067c2f1934457c106.png)
[非线性控制理论]8_三种鲁棒控制器的比较

Alibaba Tianchi SQL learning notes - Day3

TCP congestion control details | 2 background
![[comment le réseau se connecte] chapitre 6: demande d'accès au serveur et réponse au client (terminé)](/img/ef/1ac272dbd0e5c4d08a8f01f61d334d.png)
[comment le réseau se connecte] chapitre 6: demande d'accès au serveur et réponse au client (terminé)

freemarker+poi实现动态生成excel文件及解析excel文件

每日一题——小乐乐改数字

chrome浏览器快速访问stackoverflow

The bottom simulation implementation of vector

每日一题——倒置字符串

HBuilderX运行到手机或模拟器提示没有找到设备
随机推荐
Introduction to Hisilicon hi3798mv100 set top box chip [easy to understand]
SAP commerce cloud storefront framework selection: accelerator or Spartacus?
云通信接口更新迭代——SUBMAIL API V4正式上线
easyAI笔记——深度学习
vector的底层模拟实现
TCP congestion control details | 2 background
Daily question - xiaolele changes the number
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
Vscode + eslint configuration
Nexus Introduction and Xiaobai use idea Packaging and Upload to Nexus 3 private service detailed tutoriel
Alibaba Tianchi SQL learning notes - Day3
What is agile development process
维护万星开源向量数据库是什么体验
SAP commerce Cloud Architecture Overview
Example nonlinear integer programming
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
ROS知识点——消息过滤器 ( message_filters)
Microservice architecture practice: Construction of highly available distributed file system fastdfs architecture
HDU - 1114 Piggy-Bank(完全背包)
Leetcode question brushing record | 933_ Recent requests