这道题感觉挺吃力的,还用到了我不熟悉的优先队列

题目中的推导也都看明白了,总之以后还要多体会才是

这里用优先对列的原因就是因为要维护一个滑动区间的最小值,比如在区间里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的更多相关文章

  1. UVA LA 3983 - Robotruck DP,优先队列 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  2. 【暑假】[深入动态规划]UVAlive 3983 Robotruck

     UVAlive 3983 Robotruck 题目: Robotruck   Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format ...

  3. [UVALive 3983] Robotruck

    图片加载可能有点慢,请跳过题面先看题解,谢谢 设状态 \(f[i][j]\) 为,当前垃圾序号为 \(i\) ,当前承重为 \(j\) 的最小路程,好的这道题做完了 O(NC) G烂 $ $ 我们这样 ...

  4. UVALive 3983 Robotruck (单调队列,dp)

    如果状态定义为序号和重量的话,决策就是下一个垃圾捡或者不减,但是状态数太多了. 如果只定义序号作为状态的话,决策就变成从前面的某个j一直捡到i才送回垃圾. 这就变成了一个区间选最小值的问题,用单调队列 ...

  5. UVaLive 3983 Robotruck (DP + 单调队列)

    题意:有n个垃圾,第i个垃圾坐标为(xi,yi),重量为wi,有一个机器人,要按照编号从小到大的顺序剑气所有的垃圾兵扔进垃圾桶,垃圾桶在原点, 每次总重量不能超过C,两点间距离为曼哈顿距离,求出最短的 ...

  6. 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 ...

  7. 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 ...

  8. Mac Pro 使用 ll、la、l等ls的别名命令

    在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...

  9. Linux中的动态库和静态库(.a/.la/.so/.o)

    Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...

随机推荐

  1. Sqli-labs less 64

    Less-64 此处的sql语句为 $sql="SELECT * FROM security.users WHERE id=(($id)) LIMIT 0,1"; 示例payloa ...

  2. ThinkPHP3.2 分页实现

    ThinkPHP 分页实现   TP3.2框架手册,有一个数据分页,不过每次都要写太多的代码,还有中文设置等有些麻烦,做为程序开发者,有必要整理下: O.先看效果图 一.分页方法 /** * TODO ...

  3. PHP-Java-Bridge的使用(平安银行支付功能专版)

    去年做平安银行的时候,用到了PHP-Java-Bridge,后来写了一篇博客记录使用PHP-Java-Bridge的一些心得(连接:http://my.oschina.net/kenblog/blog ...

  4. ASP.NET 处理get/post数据方式

    1.GET方式 NameValueCollection coding; coding = HttpUtility.ParseQueryString(Request.Url.Query, Encodin ...

  5. Redis与Memcached的incr/decr差异对比

    目前广泛使用的分布式缓存Redis和Memcached均支持对整数型Value值的增减,对应到具体命令中就是incr和decr命令. incr/decr是原子性操作(memcached 1.2.4及以 ...

  6. POJ 2724

    Purifying Machine Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4014   Accepted: 1127 ...

  7. 理解Flight框架核心

    http://blog.csdn.net/sky_zhe/article/details/38906689 Flight 框架 Flight类 1.加载 autoload.php ,启动框架的自动加载 ...

  8. sqoop导入hdfs上的数据到oracle

    /opt/sqoop-/bin/sqoop export --table mytablename --connect jdbc:oracle:thin:@**.**.**.**:***:dbasena ...

  9. I/O复用:异步聊天

    一.I/O复用 在<TCP套接字编程>的同步聊天程序中,我们看到TCP客户同时处理两个输入:标准输入和TCP套接字.考虑在客户阻塞于标准输入fgets调用时,服务器进程被杀死,服务器TCP ...

  10. 15条规则解析JavaScript对象布局(__proto__、prototype、constructor)

    大家都说JavaScript的属性多,记不过来,各种结构复杂不易了解.确实JS是一门入门快提高难的语言,但是也有其他办法可以辅助记忆.下面就来讨论一下JS的一大难点-对象布局,究竟设计JS这门语言的人 ...