LA 3983 Robotruck
这道题感觉挺吃力的,还用到了我不熟悉的优先队列
题目中的推导也都看明白了,总之以后还要多体会才是
这里用优先对列的原因就是因为要维护一个滑动区间的最小值,比如在区间里2在1的前面,2在离开这个滑动区间会一直被1给“压迫”着,所以这个2是无用的,应当及时删除。这样的话剩下的元素都是递增的,优先队列也称单调队列也因此得名。
先把代码贴上:
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int maxn = + ;
int x[maxn], y[maxn];
int total_dist[maxn], total_weight[maxn], dist2origin[maxn];
int q[maxn], d[maxn]; int func(int i)
{
return d[i] - total_dist[i+] + dist2origin[i+];
} int main(void)
{
#ifdef LOCAL
freopen("3983in.txt", "r", stdin);
#endif int T;
scanf("%d", &T);
while(T--)
{
int c, n, w, front, rear;
scanf("%d%d", &c, &n);
total_dist[] = total_weight[] = x[] = y[] = ;
for(int i = ; i <= n; ++i)
{
scanf("%d%d%d", &x[i], &y[i], &w);
dist2origin[i] = x[i] + y[i];
total_dist[i] = total_dist[i-] + abs(x[i] - x[i-]) + abs(y[i] - y[i-]);
total_weight[i] = total_weight[i-] + w;
}
front = rear = ;
for(int i = ; i <= n; ++i)
{
while(front <= rear && total_weight[i] - total_weight[q[front]] > c)
++front;
d[i] = func(q[front]) + total_dist[i] + dist2origin[i];
while(front <= rear && func(q[rear]) >= func(i))
--rear;
q[++rear] = i;
}
printf("%d\n", d[n]);
if(T) printf("\n");
}
return ;
}
代码君
LA 3983 Robotruck的更多相关文章
- UVA LA 3983 - Robotruck DP,优先队列 难度: 2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 【暑假】[深入动态规划]UVAlive 3983 Robotruck
UVAlive 3983 Robotruck 题目: Robotruck Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format ...
- [UVALive 3983] Robotruck
图片加载可能有点慢,请跳过题面先看题解,谢谢 设状态 \(f[i][j]\) 为,当前垃圾序号为 \(i\) ,当前承重为 \(j\) 的最小路程,好的这道题做完了 O(NC) G烂 $ $ 我们这样 ...
- UVALive 3983 Robotruck (单调队列,dp)
如果状态定义为序号和重量的话,决策就是下一个垃圾捡或者不减,但是状态数太多了. 如果只定义序号作为状态的话,决策就变成从前面的某个j一直捡到i才送回垃圾. 这就变成了一个区间选最小值的问题,用单调队列 ...
- UVaLive 3983 Robotruck (DP + 单调队列)
题意:有n个垃圾,第i个垃圾坐标为(xi,yi),重量为wi,有一个机器人,要按照编号从小到大的顺序剑气所有的垃圾兵扔进垃圾桶,垃圾桶在原点, 每次总重量不能超过C,两点间距离为曼哈顿距离,求出最短的 ...
- leggere la nostra recensione del primo e del secondo
La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...
- Le lié à la légèreté semblait être et donc plus simple
Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...
- Mac Pro 使用 ll、la、l等ls的别名命令
在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...
- Linux中的动态库和静态库(.a/.la/.so/.o)
Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...
随机推荐
- 【高可用HA】Apache (1) —— Mac下安装Apache Httpd到自定义路径(非/etc/apache2)
Mac下安装Apache Httpd httpd版本: httpd-2.4.17 参考来源: Tomcat Clustering - A Step By Step Guide Apache HTTP ...
- javascript实现数据结构与算法系列:线性表的静态单链表存储结构
有时可借用一维数组来描述线性链表,这就是线性表的静态单链表存储结构. 在静态链表中,数组的一个分量表示一个结点,同时用游标(cur)代替指针指示结点在数组中的相对位置.数组的第0分量可看成头结点,其指 ...
- logback日志文件需要注意点
1.支持的jar包 logback-access-1.1.1.jarlogback-classic-1.1.1.jarlogback-core-1.1.1.jar 2.logback.xml文件,we ...
- 在 Java EE 组件中使用 Camel Routes
摘要:你可以通过集成 Camel 和 WildFly 应用服务器(使用 WildFly-Camel 子系统)在 Java EE 组件中开始使用 Apache Camel Routes. [编者按]作者 ...
- javascript 注意事项
1.submit input 标签的 type里的submit是提交表单的按钮 提交时应注意 为 标签加上 “name=""”字段和form标签,才能达到想要的效果 2.正则表达 ...
- Google NACL 简介
Back to README Getting Started This page tells you how to install Native Client and run demos, both ...
- UVA 11610 Reverse Prime (数论+树状数组+二分,难题)
参考链接http://blog.csdn.net/acm_cxlove/article/details/8264290http://blog.csdn.net/w00w12l/article/deta ...
- POJ 2181
#include <iostream> #include <cstdio> #include <cmath> #define MAXN 150005 #includ ...
- light oj 1140 - How Many Zeroes? 数位DP
思路:dp[i][j]:表示第i位数,j表示是否有0. 代码如下: #include<iostream> #include<stdio.h> #include<algor ...
- RabbitMQ安装与搭建
1.下载Erlang,最新版本是erl8.1 ,地址:http://erlang.org/download/otp_win64_19.1.exe 网上很多资料说安装后要配置环境变量,不过我安装最新的版 ...