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. ...
随机推荐
- (转)Tips for Optimizing C/C++ Code
本来要自己翻译的,随手搜索了一下,发现五天前已经有人翻译了,我就不重复发明轮子了. 转自:http://blog.csdn.net/yutianzuijin/article/details/26289 ...
- POJ 2135
Farm Tour Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10840 Accepted: 4011 Descri ...
- Webpack教程二
Webpack教程一 开发技巧 启用source-map 现在的代码是合并以后的代码,不利于排错和定位,只需要在config中添加 ... devtool: 'eval-source-map', .. ...
- 【蛙蛙推荐】Lucene.net试用
[蛙蛙推荐]Lucene.net试用 [简介] lucene.net好多人都知道的吧,反正我是最近才好好的看了一下,别笑我拿历史当新闻哦,不太了解Lucence的朋友先听我说两句哦.Lucene的 ...
- VS2003 下GridControl的列显示成图片+文字的形式实现
public RC_CustomerSolicitListUC() { // 该调用是 Windows.Forms 窗体设计器所必需的. InitializeComponent(); // TODO: ...
- poj 2311 Cutting Game 博弈论
思路:求SG函数!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<c ...
- 【bzoj2434-阿狸的打字机】AC自动机+fail树+优化
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=23083 Description 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一 ...
- CentOS系统配置solr
1.新建一个文件夹 比如soft cd /soft wget http://apache.fayea.com/lucene/solr/6.0.0/solr-6.0.0-src.tgz --下 ...
- qt中如何启动其他应用程序(如果不成功,还有许多原因即QProcess::ProcessError可供分析)
类 QDesktopServices 提供的方法 访问 常用的桌面 服务 , 如 浏览 器 . 播放器. 电子邮件客户端 . 我们 使用 QDesktopServices :: openUrl(url ...
- Linux系统监视资源与进程管理
Linux 系统中时刻运行着许多的进程,如果能够合理的管理它们,有益于系统性能的优化, 系统进程总共有五种不同的状态: 命令一:ps命令,用于查看系统中进程状态 格式:ps [参数] 查看进程与状态: ...