当前位置:网站首页>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;
}
边栏推荐
- 海思Hi3798MV100机顶盒芯片介绍[通俗易懂]
- visibilitychange – 指定标签页可见时,刷新页面数据
- class和getClass()的区别
- Platform management background and merchant menu resource management: merchant role management design
- chrome瀏覽器快速訪問stackoverflow
- PCL knowledge points - voxelized grid method for down sampling of point clouds
- SAP Commerce Cloud Storefront 框架选型:Accelerator 还是 Spartacus?
- Configure lamp+supervisor
- Five reasons to choose SAP Spartacus as the implementation framework of SAP commerce cloud storefront
- From collection to output: inventory those powerful knowledge management tools - inventory of excellent note taking software (4)
猜你喜欢

easyAI笔记——机器学习

chrome瀏覽器快速訪問stackoverflow
![[fluent] dart data type map type (create map set | initialize map set | traverse map set)](/img/02/75d21470ea0ae4cd3d17696a93d1ca.jpg)
[fluent] dart data type map type (create map set | initialize map set | traverse map set)

The difference of message mechanism between MFC and QT

Daily question - xiaolele changes the number
![[非线性控制理论]7_High gain and High Frequency](/img/e5/6c5ca4a89c97d9613cddccb281b35b.png)
[非线性控制理论]7_High gain and High Frequency

【网络是怎样连接的】第六章 请求到达服务器以及响应给客户端(完结)
![[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é)

关于我

Daily question - "number of daffodils"
随机推荐
easyAI笔记——机器学习
chrome浏览器快速访问stackoverflow
Meanings of SNAT, DNAT and masquerade in iptables
[how is the network connected] Chapter 4 explores access networks and network operators
Leetcode question brushing record | 933_ Recent requests
The difference of message mechanism between MFC and QT
Platform management background and business menu resource management: business permissions and menu resource management design
Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
Migrate your accelerator based SAP commerce cloud storefront to Spartacus
Niuke js3 separator
Schoolbag novel multithreaded crawler [easy to understand]
最长无重复子数组
什么是软件开发中的 green field 和 brown field 模式 - 绿地开发和棕地开发
13、Darknet YOLO3
云通信接口更新迭代——SUBMAIL API V4正式上线
Daily question - "number of daffodils"
TCP congestion control details | 2 background
第十五章 字符串本地化和消息字典(一)
【网络是怎么连接的】第四章 探索接入网和网络运营商
Eth data set download and related problems